Trait keyvaluedb_web::KeyValueDB
source · pub trait KeyValueDB: Sync + Send + Clone + 'static {
// Required methods
fn get<'a>(
&self,
col: u32,
key: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, Error>> + Send + 'a, Global>>;
fn delete<'a>(
&self,
col: u32,
key: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, Error>> + Send + 'a, Global>>;
fn write(
&self,
transaction: DBTransaction
) -> Pin<Box<dyn Future<Output = Result<(), DBTransactionError>> + Send, Global>>;
fn iter<'a, T, F>(
&self,
col: u32,
prefix: Option<&'a [u8]>,
f: F
) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'a, Global>>
where T: 'a,
F: FnMut((&Vec<u8, Global>, &Vec<u8, Global>)) -> Result<Option<T>, Error> + Send + Sync + 'a;
fn iter_keys<'a, T, F>(
&self,
col: u32,
prefix: Option<&'a [u8]>,
f: F
) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'a, Global>>
where T: 'a,
F: FnMut(&Vec<u8, Global>) -> Result<Option<T>, Error> + Send + Sync + 'a;
fn restore(&self, new_db: &str) -> Result<(), Error>;
// Provided methods
fn transaction(&self) -> DBTransaction { ... }
fn io_stats(&self, _kind: Kind) -> IoStats { ... }
fn has_key<'a>(
&self,
col: u32,
key: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a, Global>> { ... }
fn has_prefix<'a>(
&self,
col: u32,
prefix: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a, Global>> { ... }
fn first_with_prefix<'a>(
&self,
col: u32,
prefix: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<Option<(Vec<u8, Global>, Vec<u8, Global>)>, Error>> + Send + 'a, Global>> { ... }
}
Expand description
Generic key-value database.
The KeyValueDB
deals with “column families”, which can be thought of as distinct
stores within a database. Keys written in one column family will not be accessible from
any other. The number of column families must be specified at initialization, with a
differing interface for each database.
The API laid out here, along with the Sync
bound implies interior synchronization for
implementation.
Clone is here so we can pass an owned self to async functions, requiring interior locked mutability.
Required Methods§
sourcefn get<'a>(
&self,
col: u32,
key: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, Error>> + Send + 'a, Global>>
fn get<'a>( &self, col: u32, key: &'a [u8] ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, Error>> + Send + 'a, Global>>
Get a value by key.
sourcefn delete<'a>(
&self,
col: u32,
key: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, Error>> + Send + 'a, Global>>
fn delete<'a>( &self, col: u32, key: &'a [u8] ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, Error>> + Send + 'a, Global>>
Remove a value by key, returning the old value
sourcefn write(
&self,
transaction: DBTransaction
) -> Pin<Box<dyn Future<Output = Result<(), DBTransactionError>> + Send, Global>>
fn write( &self, transaction: DBTransaction ) -> Pin<Box<dyn Future<Output = Result<(), DBTransactionError>> + Send, Global>>
Write a transaction of changes to the backing store.
sourcefn iter<'a, T, F>(
&self,
col: u32,
prefix: Option<&'a [u8]>,
f: F
) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'a, Global>>where
T: 'a,
F: FnMut((&Vec<u8, Global>, &Vec<u8, Global>)) -> Result<Option<T>, Error> + Send + Sync + 'a,
fn iter<'a, T, F>( &self, col: u32, prefix: Option<&'a [u8]>, f: F ) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'a, Global>>where T: 'a, F: FnMut((&Vec<u8, Global>, &Vec<u8, Global>)) -> Result<Option<T>, Error> + Send + Sync + 'a,
Iterate over the data for a given column. Return all key/value pairs, optionally where the key starts with the given prefix. Iterator closure returns true for more items, false to stop iteration.
sourcefn iter_keys<'a, T, F>(
&self,
col: u32,
prefix: Option<&'a [u8]>,
f: F
) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'a, Global>>where
T: 'a,
F: FnMut(&Vec<u8, Global>) -> Result<Option<T>, Error> + Send + Sync + 'a,
fn iter_keys<'a, T, F>( &self, col: u32, prefix: Option<&'a [u8]>, f: F ) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'a, Global>>where T: 'a, F: FnMut(&Vec<u8, Global>) -> Result<Option<T>, Error> + Send + Sync + 'a,
Iterate over the data for a given column. Return all keys, optionally where the key starts with the given prefix. Iterator closure returns true for more items, false to stop iteration.
Provided Methods§
sourcefn transaction(&self) -> DBTransaction
fn transaction(&self) -> DBTransaction
Helper to create a new transaction.
sourcefn io_stats(&self, _kind: Kind) -> IoStats
fn io_stats(&self, _kind: Kind) -> IoStats
Query statistics.
Not all keyvaluedb implementations are able or expected to implement this, so by default, empty statistics is returned. Also, not all keyvaluedb implementation can return every statistic or configured to do so (some statistics gathering may impede the performance and might be off by default).
sourcefn has_key<'a>(
&self,
col: u32,
key: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a, Global>>
fn has_key<'a>( &self, col: u32, key: &'a [u8] ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a, Global>>
Check for the existence of a value by key.
Implementations on Foreign Types§
source§impl KeyValueDB for InMemory
impl KeyValueDB for InMemory
source§fn delete<'a>(
&self,
col: u32,
key: &'a [u8]
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, Error>> + Send + 'a, Global>>
fn delete<'a>( &self, col: u32, key: &'a [u8] ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8, Global>>, Error>> + Send + 'a, Global>>
Remove a value by key, returning the old value