pub trait Database {
type Config: Default;
// Required methods
fn new(config: Self::Config) -> PmtreeResult<Self>
where Self: Sized;
fn load(config: Self::Config) -> PmtreeResult<Self>
where Self: Sized;
fn get(&self, key: DBKey) -> PmtreeResult<Option<Value>>;
fn put(&mut self, key: DBKey, value: Value) -> PmtreeResult<()>;
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> PmtreeResult<()>;
fn close(&mut self) -> PmtreeResult<()>;
}
Expand description
Trait that must be implemented for a Database
Required Associated Types§
Required Methods§
Sourcefn new(config: Self::Config) -> PmtreeResult<Self>where
Self: Sized,
fn new(config: Self::Config) -> PmtreeResult<Self>where
Self: Sized,
Creates new instance of db
Sourcefn load(config: Self::Config) -> PmtreeResult<Self>where
Self: Sized,
fn load(config: Self::Config) -> PmtreeResult<Self>where
Self: Sized,
Loades existing db (existence check required)
Sourcefn put(&mut self, key: DBKey, value: Value) -> PmtreeResult<()>
fn put(&mut self, key: DBKey, value: Value) -> PmtreeResult<()>
Puts the value to the db by the key
Sourcefn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> PmtreeResult<()>
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> PmtreeResult<()>
Puts the leaves batch to the db
Sourcefn close(&mut self) -> PmtreeResult<()>
fn close(&mut self) -> PmtreeResult<()>
Closes the db connection