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§

source

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.

source

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

source

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

Write a transaction of changes to the backing store.

source

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.

source

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.

source

fn restore(&self, new_db: &str) -> Result<(), Error>

Attempt to replace this database with a new one located at the given path.

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>( &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.

source

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

Check for the existence of a value by prefix.

source

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

Get the first value matching the given prefix.

Implementations on Foreign Types§

source§

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

Remove a value by key, returning the old value

source§

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

source§

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

source§

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,

source§

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,

source§

fn restore(&self, _new_db: &str) -> Result<(), Error>

Implementors§