zk_kit_pmt/
database.rs

1use crate::*;
2
3use std::collections::HashMap;
4
5/// Trait that must be implemented for a Database
6pub trait Database {
7    /// Config for database. Default is necessary for a default() pmtree function
8    type Config: Default;
9
10    /// Creates new instance of db
11    fn new(config: Self::Config) -> PmtreeResult<Self>
12    where
13        Self: Sized;
14
15    /// Loades existing db (existence check required)
16    fn load(config: Self::Config) -> PmtreeResult<Self>
17    where
18        Self: Sized;
19
20    /// Returns value from db by the key
21    fn get(&self, key: DBKey) -> PmtreeResult<Option<Value>>;
22
23    /// Puts the value to the db by the key
24    fn put(&mut self, key: DBKey, value: Value) -> PmtreeResult<()>;
25
26    /// Puts the leaves batch to the db
27    fn put_batch(&mut self, subtree: HashMap<DBKey, Value>) -> PmtreeResult<()>;
28
29    /// Closes the db connection
30    fn close(&mut self) -> PmtreeResult<()>;
31}