Skip to main content

aimdb_persistence/
lib.rs

1//! # aimdb-persistence
2//!
3//! Optional persistence layer for AimDB. Persistence is implemented as a
4//! **buffer subscriber** — just like `.tap()` — keeping it fully within
5//! AimDB's existing producer–consumer architecture.
6//!
7//! This crate provides:
8//!
9//! - [`PersistenceBackend`] trait for pluggable backends (SQLite, Postgres, …)
10//! - [`AimDbBuilderPersistExt`] — adds `.with_persistence()` to the builder
11//! - [`RecordRegistrarPersistExt`] — adds `.persist()` to record registration
12//! - [`AimDbQueryExt`] — adds `.query_latest()` / `.query_range()` to `AimDb<R>`
13//!
14//! # Usage
15//!
16//! ```rust,ignore
17//! use aimdb_persistence::{AimDbBuilderPersistExt, RecordRegistrarPersistExt, AimDbQueryExt};
18//! use aimdb_persistence_sqlite::SqliteBackend;
19//!
20//! let backend = Arc::new(SqliteBackend::new("./data/history.db")?);
21//!
22//! let mut builder = AimDbBuilder::new()
23//!     .runtime(runtime)
24//!     .with_persistence(backend.clone(), Duration::from_secs(7 * 24 * 3600));
25//!
26//! builder.configure::<MyRecord>(key, |reg| {
27//!     reg.buffer(BufferCfg::SpmcRing { capacity: 500 })
28//!        .persist(key.to_string());
29//! });
30//!
31//! let db = builder.build().await?;
32//!
33//! // Query historical data
34//! let latest: Vec<MyRecord> = db.query_latest("my_record::*", 1).await?;
35//! ```
36
37pub mod backend;
38pub mod builder_ext;
39pub mod error;
40pub mod ext;
41pub mod query_ext;
42
43// Re-exports for convenience
44pub use backend::{BoxFuture, PersistenceBackend, QueryParams, StoredValue};
45pub use builder_ext::{AimDbBuilderPersistExt, PersistenceState};
46pub use error::PersistenceError;
47pub use ext::RecordRegistrarPersistExt;
48pub use query_ext::AimDbQueryExt;