mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-10 21:04:59 +00:00
240e579066
* cargo: replace `sanakirja` with `redb` * database: update docs `sanakirja` -> `redb` * lib: add TODO for `ConcreteEnv` generic replacement * database: split `trait Database` -> `trait Database{Read,Write}` * heed: add `struct HeedTable{Ro,Rw}` to match `redb` behavior * ops: remove imports for now * env: fix `&mut` bound on RwTx * database: impl `redb`, type-checks * fix heed trait impls, `Database{Read,Write}` -> `Database{Ro,Rw}` * redb: impl `From<_>` for `RuntimeError` * update readme * heed: document `HeedTableR{o,w}` types * env: doc `sync()` invariant * database: document data & lock filenames * misc docs, `redb` durability impl, `'db` -> `'env` * redb: fixes * misc docs and fixes * Update database/README.md Co-authored-by: Boog900 <boog900@tutanota.com> --------- Co-authored-by: Boog900 <boog900@tutanota.com>
74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
//! General constants used throughout `cuprate-database`.
|
|
|
|
//---------------------------------------------------------------------------------------------------- Import
|
|
use cfg_if::cfg_if;
|
|
|
|
//---------------------------------------------------------------------------------------------------- Error Messages
|
|
/// Corrupt database error message.
|
|
///
|
|
/// The error message shown to end-users in panic
|
|
/// messages if we think the database is corrupted.
|
|
///
|
|
/// This is meant to be user-friendly.
|
|
pub const DATABASE_CORRUPT_MSG: &str = r"Cuprate has encountered a fatal error. The database may be corrupted.
|
|
|
|
TODO: instructions on:
|
|
1. What to do
|
|
2. How to fix (re-sync, recover, etc)
|
|
3. General advice for preventing corruption
|
|
4. etc";
|
|
|
|
//---------------------------------------------------------------------------------------------------- Misc
|
|
/// Static string of the `crate` being used as the database backend.
|
|
///
|
|
/// | Backend | Value |
|
|
/// |---------|-------|
|
|
/// | `heed` | "heed"
|
|
/// | `redb` | "redb"
|
|
pub const DATABASE_BACKEND: &str = {
|
|
cfg_if! {
|
|
if #[cfg(all(feature = "redb", not(feature = "heed")))] {
|
|
"redb"
|
|
} else {
|
|
"heed"
|
|
}
|
|
}
|
|
};
|
|
|
|
/// Cuprate's database filename.
|
|
///
|
|
/// Used in [`Config::db_file`](crate::config::Config::db_file).
|
|
///
|
|
/// | Backend | Value |
|
|
/// |---------|-------|
|
|
/// | `heed` | "data.mdb"
|
|
/// | `redb` | "data.redb"
|
|
pub const DATABASE_DATA_FILENAME: &str = {
|
|
cfg_if! {
|
|
if #[cfg(all(feature = "redb", not(feature = "heed")))] {
|
|
"data.redb"
|
|
} else {
|
|
"data.mdb"
|
|
}
|
|
}
|
|
};
|
|
|
|
/// Cuprate's database lock filename.
|
|
///
|
|
/// | Backend | Value |
|
|
/// |---------|-------|
|
|
/// | `heed` | Some("lock.mdb")
|
|
/// | `redb` | None (redb doesn't use a file lock)
|
|
pub const DATABASE_LOCK_FILENAME: Option<&str> = {
|
|
cfg_if! {
|
|
if #[cfg(all(feature = "redb", not(feature = "heed")))] {
|
|
None
|
|
} else {
|
|
Some("lock.mdb")
|
|
}
|
|
}
|
|
};
|
|
|
|
//---------------------------------------------------------------------------------------------------- Tests
|
|
#[cfg(test)]
|
|
mod test {}
|