pub mod backfill_queue; pub mod error; pub mod firehose_cursor; pub mod preferences; pub use error::{StorageError, StorageResult}; use std::path::Path; use std::sync::Arc; /// Fixed-length 3-byte key prefix per data type. pub(crate) type KeyPrefix = [u8; 3]; pub(crate) const PREFIX_PREFS: KeyPrefix = *b"prf"; pub(crate) const PREFIX_FH_CURSOR: KeyPrefix = *b"fhc"; pub(crate) const PREFIX_BACKFILL: KeyPrefix = *b"bfq"; /// Shared handle to the fjall database and its keyspaces. pub struct Db { pub(crate) database: fjall::Database, /// Durable state: preferences, queue jobs, firehose cursor. pub(crate) persistent: fjall::Keyspace, /// Ephemeral cache — currently unused; kept as a home for future read-through caches. #[allow(dead_code)] pub(crate) cache: fjall::Keyspace, } pub type DbRef = Arc; /// Open (or create) the fjall database at `path` and return a shared handle. pub fn open(path: &Path) -> StorageResult { let database = fjall::Database::builder(path).open()?; let persistent = database.keyspace("persistent", fjall::KeyspaceCreateOptions::default)?; let cache = database.keyspace("cache", fjall::KeyspaceCreateOptions::default)?; Ok(Arc::new(Db { database, persistent, cache, })) }