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 {
|
2023-02-10 14:52:45 +04:00
|
|
|
/// Config for database. Default is necessary for a default() pmtree function
|
|
|
|
|
type Config: Default;
|
|
|
|
|
|
2022-10-28 16:42:13 +03:00
|
|
|
/// 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;
|
2022-10-29 13:45:25 +03:00
|
|
|
|
2022-10-28 16:42:13 +03:00
|
|
|
/// 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;
|
2022-10-29 13:45:25 +03:00
|
|
|
|
2022-10-28 16:42:13 +03:00
|
|
|
/// Returns value from db by the key
|
2023-04-18 14:22:38 +05:30
|
|
|
fn get(&self, key: DBKey) -> PmtreeResult<Option<Value>>;
|
2022-10-29 13:45:25 +03:00
|
|
|
|
2022-10-28 16:42:13 +03:00
|
|
|
/// 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
|
|
|
}
|