pub trait DB {
// Required methods
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Error>;
fn contains(&self, key: &[u8]) -> Result<bool, Error>;
fn insert(&self, key: Vec<u8>, value: Vec<u8>) -> Result<(), Error>;
fn remove(&self, key: &[u8]) -> Result<(), Error>;
fn flush(&self) -> Result<(), Error>;
// Provided methods
fn insert_batch(
&self,
keys: Vec<Vec<u8>>,
values: Vec<Vec<u8>>
) -> Result<(), Error> { ... }
fn remove_batch(&self, keys: &[Vec<u8>]) -> Result<(), Error> { ... }
}
Expand description
“DB” defines the “trait” of trie and database interaction. You should first write the data to the cache and write the data to the database in bulk after the end of a set of operations.