Skip to main content

StorageBackend

Trait StorageBackend 

Source
pub trait StorageBackend: Send + Sync {
    // Required methods
    fn insert(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>;
    fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>;
    fn delete(&self, table: &str, key: &[u8]) -> DbxResult<bool>;
    fn scan<R: RangeBounds<Vec<u8>> + Clone>(
        &self,
        table: &str,
        range: R,
    ) -> DbxResult<Vec<(Vec<u8>, Vec<u8>)>>;
    fn scan_one<R: RangeBounds<Vec<u8>> + Clone>(
        &self,
        table: &str,
        range: R,
    ) -> DbxResult<Option<(Vec<u8>, Vec<u8>)>>;
    fn flush(&self) -> DbxResult<()>;
    fn count(&self, table: &str) -> DbxResult<usize>;
    fn table_names(&self) -> DbxResult<Vec<String>>;

    // Provided method
    fn insert_batch(
        &self,
        table: &str,
        rows: Vec<(Vec<u8>, Vec<u8>)>,
    ) -> DbxResult<()> { ... }
}
Expand description

Core storage interface — all tiers implement this trait.

§Design Principles

  • DIP: SQL layer depends on this trait, never on concrete types.
  • Strategy: New storage tiers are added by implementing this trait.
  • Thread Safety: Send + Sync required for concurrent access.

§Contract

  • insert: Upsert semantics — overwrites existing key.
  • get: Returns None for non-existent keys, never errors.
  • delete: Returns true if key existed, false otherwise.
  • scan: Returns key-value pairs in key order within range.
  • flush: Persists buffered data to durable storage.
  • count: Returns the number of keys in a table.
  • table_names: Returns all table names.

Required Methods§

Source

fn insert(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>

Insert a key-value pair.

Source

fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>

Get a value by key.

Source

fn delete(&self, table: &str, key: &[u8]) -> DbxResult<bool>

Delete a key-value pair.

Source

fn scan<R: RangeBounds<Vec<u8>> + Clone>( &self, table: &str, range: R, ) -> DbxResult<Vec<(Vec<u8>, Vec<u8>)>>

Scan a range of keys.

Source

fn scan_one<R: RangeBounds<Vec<u8>> + Clone>( &self, table: &str, range: R, ) -> DbxResult<Option<(Vec<u8>, Vec<u8>)>>

Scan a single key-value pair in a range (optimized).

Source

fn flush(&self) -> DbxResult<()>

Flush any buffered data to durable storage.

Source

fn count(&self, table: &str) -> DbxResult<usize>

Return the number of keys in the given table.

Source

fn table_names(&self) -> DbxResult<Vec<String>>

Return all table names managed by this backend.

Provided Methods§

Source

fn insert_batch( &self, table: &str, rows: Vec<(Vec<u8>, Vec<u8>)>, ) -> DbxResult<()>

Insert multiple key-value pairs in a batch (optimized).

Default implementation calls insert() sequentially. Implementations should override this for better performance.

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§