Files

29 lines
805 B
Rust
Raw Permalink Normal View History

2022-10-19 15:10:43 +03:00
use crate::*;
2023-02-02 14:31:18 +04:00
use std::collections::HashMap;
2022-10-19 15:10:43 +03:00
/// Trait that must be implemented for a Database
pub trait Database {
/// Config for database. Default is necessary for a default() pmtree function
type Config: Default;
/// Creates new instance of db
2023-04-18 14:22:38 +05:30
fn new(config: Self::Config) -> PmtreeResult<Self>
2022-11-06 15:00:09 +03:00
where
Self: Sized;
/// Loades existing db (existence check required)
2023-04-18 14:22:38 +05:30
fn load(config: Self::Config) -> PmtreeResult<Self>
2022-11-06 15:00:09 +03:00
where
Self: Sized;
/// Returns value from db by the key
2023-04-18 14:22:38 +05:30
fn get(&self, key: DBKey) -> PmtreeResult<Option<Value>>;
/// Puts the value to the db by the key
2023-04-18 14:22:38 +05:30
fn put(&mut self, key: DBKey, value: Value) -> PmtreeResult<()>;
2023-02-02 14:31:18 +04:00
/// Batc
2023-04-18 14:22:38 +05:30
fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> PmtreeResult<()>;
2022-10-19 15:10:43 +03:00
}