2023-11-05 14:47:24 +00:00
|
|
|
mod create_db;
|
|
|
|
pub use create_db::*;
|
|
|
|
|
2023-07-13 23:09:11 +00:00
|
|
|
mod mem;
|
|
|
|
pub use mem::*;
|
|
|
|
|
|
|
|
#[cfg(feature = "rocksdb")]
|
|
|
|
mod rocks;
|
2023-07-26 01:39:29 +00:00
|
|
|
#[cfg(feature = "rocksdb")]
|
|
|
|
pub use rocks::{RocksDB, new_rocksdb};
|
2023-04-14 15:41:01 +00:00
|
|
|
|
2023-11-30 09:22:37 +00:00
|
|
|
#[cfg(feature = "parity-db")]
|
|
|
|
mod parity_db;
|
|
|
|
#[cfg(feature = "parity-db")]
|
|
|
|
pub use parity_db::{ParityDb, new_parity_db};
|
|
|
|
|
2023-04-14 15:41:01 +00:00
|
|
|
/// An object implementing get.
|
2023-07-13 23:09:11 +00:00
|
|
|
pub trait Get {
|
2023-04-14 15:41:01 +00:00
|
|
|
fn get(&self, key: impl AsRef<[u8]>) -> Option<Vec<u8>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// An atomic database operation.
|
2023-04-14 19:04:26 +00:00
|
|
|
#[must_use]
|
2023-07-13 23:09:11 +00:00
|
|
|
pub trait DbTxn: Send + Get {
|
2023-04-14 15:41:01 +00:00
|
|
|
fn put(&mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>);
|
|
|
|
fn del(&mut self, key: impl AsRef<[u8]>);
|
|
|
|
fn commit(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A database supporting atomic operations.
|
2023-07-13 23:09:11 +00:00
|
|
|
pub trait Db: 'static + Send + Sync + Clone + Get {
|
2023-04-14 15:41:01 +00:00
|
|
|
type Transaction<'a>: DbTxn;
|
|
|
|
fn key(db_dst: &'static [u8], item_dst: &'static [u8], key: impl AsRef<[u8]>) -> Vec<u8> {
|
|
|
|
let db_len = u8::try_from(db_dst.len()).unwrap();
|
|
|
|
let dst_len = u8::try_from(item_dst.len()).unwrap();
|
2023-07-08 15:29:05 +00:00
|
|
|
[[db_len].as_ref(), db_dst, [dst_len].as_ref(), item_dst, key.as_ref()].concat()
|
2023-04-14 15:41:01 +00:00
|
|
|
}
|
|
|
|
fn txn(&mut self) -> Self::Transaction<'_>;
|
|
|
|
}
|