1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::*;

use std::collections::HashMap;

/// 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
    fn new(config: Self::Config) -> PmtreeResult<Self>
    where
        Self: Sized;

    /// Loades existing db (existence check required)
    fn load(config: Self::Config) -> PmtreeResult<Self>
    where
        Self: Sized;

    /// Returns value from db by the key
    fn get(&self, key: DBKey) -> PmtreeResult<Option<Value>>;

    /// Puts the value to the db by the key
    fn put(&mut self, key: DBKey, value: Value) -> PmtreeResult<()>;

    /// Puts the leaves batch to the db
    fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> PmtreeResult<()>;

    /// Closes the db connection
    fn close(&mut self) -> PmtreeResult<()>;
}