Trait KeyValueDatabase

Source
pub trait KeyValueDatabase:
    WithError
    + Sized
    + Send
    + Sync {
    type Config: Send + Sync;
    type Store;

    // Required methods
    fn get_name() -> String;
    fn connect(
        config: &Self::Config,
        namespace: &str,
    ) -> impl Future<Output = Result<Self, Self::Error>> + Send + Sync;
    fn open_shared(&self, root_key: &[u8]) -> Result<Self::Store, Self::Error>;
    fn open_exclusive(
        &self,
        root_key: &[u8],
    ) -> Result<Self::Store, Self::Error>;
    fn list_all(
        config: &Self::Config,
    ) -> impl Future<Output = Result<Vec<String>, Self::Error>> + Send + Sync;
    fn list_root_keys(
        config: &Self::Config,
        namespace: &str,
    ) -> impl Future<Output = Result<Vec<Vec<u8>>, Self::Error>> + Send + Sync;
    fn exists(
        config: &Self::Config,
        namespace: &str,
    ) -> impl Future<Output = Result<bool, Self::Error>> + Send + Sync;
    fn create(
        config: &Self::Config,
        namespace: &str,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send + Sync;
    fn delete(
        config: &Self::Config,
        namespace: &str,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send + Sync;

    // Provided methods
    fn delete_all(
        config: &Self::Config,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send + Sync { ... }
    fn maybe_create_and_connect(
        config: &Self::Config,
        namespace: &str,
    ) -> impl Future<Output = Result<Self, Self::Error>> + Send + Sync { ... }
    fn recreate_and_connect(
        config: &Self::Config,
        namespace: &str,
    ) -> impl Future<Output = Result<Self, Self::Error>> + Send + Sync { ... }
}
Expand description

The definition of a key-value database.

Required Associated Types§

Source

type Config: Send + Sync

The configuration needed to interact with a new backend.

Source

type Store

The result of opening a partition.

Required Methods§

Source

fn get_name() -> String

The name of this database.

Source

fn connect( config: &Self::Config, namespace: &str, ) -> impl Future<Output = Result<Self, Self::Error>> + Send + Sync

Connects to an existing namespace using the given configuration.

Source

fn open_shared(&self, root_key: &[u8]) -> Result<Self::Store, Self::Error>

Opens a shared partition starting at root_key. It is understood that the partition MAY be read and written simultaneously from other clients.

Source

fn open_exclusive(&self, root_key: &[u8]) -> Result<Self::Store, Self::Error>

Opens an exclusive partition starting at root_key. It is assumed that the partition WILL NOT be read and written simultaneously by other clients.

IMPORTANT: This assumption is not enforced at the moment. However, future implementations may choose to return an error if another client is detected.

Source

fn list_all( config: &Self::Config, ) -> impl Future<Output = Result<Vec<String>, Self::Error>> + Send + Sync

Obtains the list of existing namespaces.

Source

fn list_root_keys( config: &Self::Config, namespace: &str, ) -> impl Future<Output = Result<Vec<Vec<u8>>, Self::Error>> + Send + Sync

Lists the root keys of the namespace. It is possible that some root keys have no keys.

Source

fn exists( config: &Self::Config, namespace: &str, ) -> impl Future<Output = Result<bool, Self::Error>> + Send + Sync

Tests if a given namespace exists.

Source

fn create( config: &Self::Config, namespace: &str, ) -> impl Future<Output = Result<(), Self::Error>> + Send + Sync

Creates a namespace. Returns an error if the namespace exists.

Source

fn delete( config: &Self::Config, namespace: &str, ) -> impl Future<Output = Result<(), Self::Error>> + Send + Sync

Deletes the given namespace.

Provided Methods§

Source

fn delete_all( config: &Self::Config, ) -> impl Future<Output = Result<(), Self::Error>> + Send + Sync

Deletes all the existing namespaces.

Source

fn maybe_create_and_connect( config: &Self::Config, namespace: &str, ) -> impl Future<Output = Result<Self, Self::Error>> + Send + Sync

Initializes a storage if missing and provides it.

Source

fn recreate_and_connect( config: &Self::Config, namespace: &str, ) -> impl Future<Output = Result<Self, Self::Error>> + Send + Sync

Creates a new storage. Overwrites it if this namespace already exists.

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.

Implementors§

Source§

impl KeyValueDatabase for DynamoDbDatabaseInternal

Source§

impl KeyValueDatabase for MemoryDatabase

Source§

impl KeyValueDatabase for RocksDbDatabaseInternal

Source§

impl KeyValueDatabase for ScyllaDbDatabaseInternal

Source§

impl<D1, D2, A> KeyValueDatabase for DualDatabase<D1, D2, A>

Source§

impl<D> KeyValueDatabase for JournalingKeyValueDatabase<D>

Source§

impl<D> KeyValueDatabase for LruCachingDatabase<D>

Source§

impl<D> KeyValueDatabase for MeteredDatabase<D>

Source§

impl<D> KeyValueDatabase for ValueSplittingDatabase<D>
where D: KeyValueDatabase, D::Error: 'static,