KeyValueDB

Trait KeyValueDB 

Source
pub trait KeyValueDB:
    Sync
    + Send
    + Clone
    + 'static {
Show 13 methods // Required methods fn get<'a>( &'a self, col: u32, key: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'a>>; fn delete<'a>( &'a self, col: u32, key: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'a>>; fn write( &self, transaction: DBTransaction, ) -> Pin<Box<dyn Future<Output = Result<(), DBTransactionError>> + Send + '_>>; fn iter<'a, T, C, F>( &'a self, col: u32, prefix: Option<&'a [u8]>, context: C, f: F, ) -> Pin<Box<dyn Future<Output = Result<(C, Option<T>), Error>> + Send + 'a>> where T: Send + 'static, C: Send + 'static, F: FnMut(&mut C, (&Vec<u8>, &Vec<u8>)) -> Result<Option<T>, Error> + Send + Sync + 'static; fn iter_keys<'a, T, C, F>( &'a self, col: u32, prefix: Option<&'a [u8]>, context: C, f: F, ) -> Pin<Box<dyn Future<Output = Result<(C, Option<T>), Error>> + Send + 'a>> where T: Send + 'static, C: Send + 'static, F: FnMut(&mut C, &Vec<u8>) -> Result<Option<T>, Error> + Send + Sync + 'static; fn num_columns(&self) -> Result<u32, Error>; fn num_keys( &self, col: u32, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + '_>>; // Provided methods fn transaction(&self) -> DBTransaction { ... } fn io_stats(&self, _kind: Kind) -> IoStats { ... } fn has_key<'a>( &'a self, col: u32, key: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>> { ... } fn has_prefix<'a>( &'a self, col: u32, prefix: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>> { ... } fn first_with_prefix<'a>( &'a self, col: u32, prefix: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<(Vec<u8>, Vec<u8>)>, Error>> + Send + 'a>> { ... } fn cleanup( &self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>> { ... }
}
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§

Source

fn get<'a>( &'a self, col: u32, key: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'a>>

Get a value by key.

Source

fn delete<'a>( &'a self, col: u32, key: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'a>>

Remove a value by key, returning the old value

Source

fn write( &self, transaction: DBTransaction, ) -> Pin<Box<dyn Future<Output = Result<(), DBTransactionError>> + Send + '_>>

Write a transaction of changes to the backing store.

Source

fn iter<'a, T, C, F>( &'a self, col: u32, prefix: Option<&'a [u8]>, context: C, f: F, ) -> Pin<Box<dyn Future<Output = Result<(C, Option<T>), Error>> + Send + 'a>>
where T: Send + 'static, C: Send + 'static, F: FnMut(&mut C, (&Vec<u8>, &Vec<u8>)) -> Result<Option<T>, Error> + Send + Sync + 'static,

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.

Source

fn iter_keys<'a, T, C, F>( &'a self, col: u32, prefix: Option<&'a [u8]>, context: C, f: F, ) -> Pin<Box<dyn Future<Output = Result<(C, Option<T>), Error>> + Send + 'a>>
where T: Send + 'static, C: Send + 'static, F: FnMut(&mut C, &Vec<u8>) -> Result<Option<T>, Error> + Send + Sync + 'static,

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.

Source

fn num_columns(&self) -> Result<u32, Error>

The number of column families in the db.

Source

fn num_keys( &self, col: u32, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + '_>>

The number of keys in a column (estimated).

Provided Methods§

Source

fn transaction(&self) -> DBTransaction

Helper to create a new transaction.

Source

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).

Source

fn has_key<'a>( &'a self, col: u32, key: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>

Check for the existence of a value by key.

Source

fn has_prefix<'a>( &'a self, col: u32, prefix: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'a>>

Check for the existence of a value by prefix.

Source

fn first_with_prefix<'a>( &'a self, col: u32, prefix: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<(Vec<u8>, Vec<u8>)>, Error>> + Send + 'a>>

Get the first value matching the given prefix.

Source

fn cleanup( &self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + '_>>

Cleanup/Vacuum database

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl KeyValueDB for InMemory

Source§

fn delete<'a>( &'a self, col: u32, key: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'a>>

Remove a value by key, returning the old value

Source§

fn get<'a>( &'a self, col: u32, key: &'a [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'a>>

Source§

fn write( &self, transaction: DBTransaction, ) -> Pin<Box<dyn Future<Output = Result<(), DBTransactionError>> + Send + '_>>

Source§

fn iter<'a, T, C, F>( &'a self, col: u32, prefix: Option<&'a [u8]>, context: C, f: F, ) -> Pin<Box<dyn Future<Output = Result<(C, Option<T>), Error>> + Send + 'a>>
where T: Send + 'static, C: Send + 'static, F: FnMut(&mut C, (&Vec<u8>, &Vec<u8>)) -> Result<Option<T>, Error> + Send + Sync + 'static,

Source§

fn iter_keys<'a, T, C, F>( &'a self, col: u32, prefix: Option<&'a [u8]>, context: C, f: F, ) -> Pin<Box<dyn Future<Output = Result<(C, Option<T>), Error>> + Send + 'a>>
where T: Send + 'static, C: Send + 'static, F: FnMut(&mut C, &Vec<u8>) -> Result<Option<T>, Error> + Send + Sync + 'static,

Source§

fn num_columns(&self) -> Result<u32, Error>

Source§

fn num_keys( &self, col: u32, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + '_>>

Implementors§