pub trait KeyValueDB: Sync + Send {
    // Required methods
    fn get(
        &self,
        col: u32,
        key: &[u8]
    ) -> Result<Option<Vec<u8, Global>>, Error>;
    fn get_by_prefix(
        &self,
        col: u32,
        prefix: &[u8]
    ) -> Result<Option<Vec<u8, Global>>, Error>;
    fn write(&self, transaction: DBTransaction) -> Result<(), Error>;
    fn iter<'a>(
        &'a self,
        col: u32
    ) -> Box<dyn Iterator<Item = Result<(SmallVec<[u8; 32]>, Vec<u8, Global>), Error>> + 'a, Global>;
    fn iter_with_prefix<'a>(
        &'a self,
        col: u32,
        prefix: &'a [u8]
    ) -> Box<dyn Iterator<Item = Result<(SmallVec<[u8; 32]>, Vec<u8, Global>), Error>> + 'a, Global>;

    // Provided methods
    fn transaction(&self) -> DBTransaction { ... }
    fn io_stats(&self, _kind: Kind) -> IoStats { ... }
    fn has_key(&self, col: u32, key: &[u8]) -> Result<bool, Error> { ... }
    fn has_prefix(&self, col: u32, prefix: &[u8]) -> Result<bool, Error> { ... }
}
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.

Required Methods§

source

fn get(&self, col: u32, key: &[u8]) -> Result<Option<Vec<u8, Global>>, Error>

Get a value by key.

source

fn get_by_prefix( &self, col: u32, prefix: &[u8] ) -> Result<Option<Vec<u8, Global>>, Error>

Get the first value matching the given prefix.

source

fn write(&self, transaction: DBTransaction) -> Result<(), Error>

Write a transaction of changes to the backing store.

source

fn iter<'a>( &'a self, col: u32 ) -> Box<dyn Iterator<Item = Result<(SmallVec<[u8; 32]>, Vec<u8, Global>), Error>> + 'a, Global>

Iterate over the data for a given column.

source

fn iter_with_prefix<'a>( &'a self, col: u32, prefix: &'a [u8] ) -> Box<dyn Iterator<Item = Result<(SmallVec<[u8; 32]>, Vec<u8, Global>), Error>> + 'a, Global>

Iterate over the data for a given column, returning all key/value pairs where the key starts with the given prefix.

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 kvdb implementations are able or expected to implement this, so by default, empty statistics is returned. Also, not all kvdb implementations 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(&self, col: u32, key: &[u8]) -> Result<bool, Error>

Check for the existence of a value by key.

source

fn has_prefix(&self, col: u32, prefix: &[u8]) -> Result<bool, Error>

Check for the existence of a value by prefix.

Implementations on Foreign Types§

source§

impl KeyValueDB for Database

source§

fn get(&self, col: u32, key: &[u8]) -> Result<Option<Vec<u8, Global>>, Error>

source§

fn get_by_prefix( &self, col: u32, prefix: &[u8] ) -> Result<Option<Vec<u8, Global>>, Error>

source§

fn write(&self, transaction: DBTransaction) -> Result<(), Error>

source§

fn iter<'a>( &'a self, col: u32 ) -> Box<dyn Iterator<Item = Result<(SmallVec<[u8; 32]>, Vec<u8, Global>), Error>> + 'a, Global>

source§

fn iter_with_prefix<'a>( &'a self, col: u32, prefix: &'a [u8] ) -> Box<dyn Iterator<Item = Result<(SmallVec<[u8; 32]>, Vec<u8, Global>), Error>> + 'a, Global>

source§

fn io_stats(&self, kind: Kind) -> IoStats

source§

impl KeyValueDB for InMemory

source§

fn get(&self, col: u32, key: &[u8]) -> Result<Option<Vec<u8, Global>>, Error>

source§

fn get_by_prefix( &self, col: u32, prefix: &[u8] ) -> Result<Option<Vec<u8, Global>>, Error>

source§

fn write(&self, transaction: DBTransaction) -> Result<(), Error>

source§

fn iter<'a>( &'a self, col: u32 ) -> Box<dyn Iterator<Item = Result<(SmallVec<[u8; 32]>, Vec<u8, Global>), Error>> + 'a, Global>

source§

fn iter_with_prefix<'a>( &'a self, col: u32, prefix: &'a [u8] ) -> Box<dyn Iterator<Item = Result<(SmallVec<[u8; 32]>, Vec<u8, Global>), Error>> + 'a, Global>

Implementors§

source§

impl KeyValueDB for polkadot_node_subsystem_util::database::paritydb_impl::DbAdapter

source§

impl<D: KeyValueDB> KeyValueDB for polkadot_node_subsystem_util::database::kvdb_impl::DbAdapter<D>