Skip to main content

PersistenceBackend

Trait PersistenceBackend 

Source
pub trait PersistenceBackend: Send + Sync {
    // Required methods
    fn store<'a>(
        &'a self,
        record_name: &'a str,
        value: &'a Value,
        timestamp: u64,
    ) -> BoxFuture<'a, Result<(), PersistenceError>>;
    fn query<'a>(
        &'a self,
        record_pattern: &'a str,
        params: QueryParams,
    ) -> BoxFuture<'a, Result<Vec<StoredValue>, PersistenceError>>;
    fn cleanup(
        &self,
        older_than: u64,
    ) -> BoxFuture<'_, Result<u64, PersistenceError>>;

    // Provided method
    fn initialize(&self) -> BoxFuture<'_, Result<(), PersistenceError>> { ... }
}
Expand description

Pluggable persistence backend.

Implementations run on a concrete async runtime (e.g. Tokio). The trait uses manual BoxFuture instead of async_trait for consistency with the rest of the AimDB codebase.

Required Methods§

Source

fn store<'a>( &'a self, record_name: &'a str, value: &'a Value, timestamp: u64, ) -> BoxFuture<'a, Result<(), PersistenceError>>

Store a JSON value for a record.

Source

fn query<'a>( &'a self, record_pattern: &'a str, params: QueryParams, ) -> BoxFuture<'a, Result<Vec<StoredValue>, PersistenceError>>

Query stored values, with optional pattern and time-range support.

record_pattern supports * as a glob wildcard. For example, "accuracy::*" matches all records whose name starts with "accuracy::".

Source

fn cleanup( &self, older_than: u64, ) -> BoxFuture<'_, Result<u64, PersistenceError>>

Delete all rows older than older_than (Unix ms).

Called automatically by the retention cleanup task registered during with_persistence(). Can also be called explicitly.

Provided Methods§

Source

fn initialize(&self) -> BoxFuture<'_, Result<(), PersistenceError>>

Initialize storage (create tables, indexes, …).

Default: no-op. Backends that perform setup eagerly in ::new() (like SqliteBackend) do not need to override this.

Implementors§