ceres: a small planet in a giant solar system
32
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 40 lines 1.3 kB view raw
1pub mod backfill_queue; 2pub mod error; 3pub mod firehose_cursor; 4pub mod preferences; 5 6pub use error::{StorageError, StorageResult}; 7 8use std::path::Path; 9use std::sync::Arc; 10 11/// Fixed-length 3-byte key prefix per data type. 12pub(crate) type KeyPrefix = [u8; 3]; 13 14pub(crate) const PREFIX_PREFS: KeyPrefix = *b"prf"; 15pub(crate) const PREFIX_FH_CURSOR: KeyPrefix = *b"fhc"; 16pub(crate) const PREFIX_BACKFILL: KeyPrefix = *b"bfq"; 17 18/// Shared handle to the fjall database and its keyspaces. 19pub struct Db { 20 pub(crate) database: fjall::Database, 21 /// Durable state: preferences, queue jobs, firehose cursor. 22 pub(crate) persistent: fjall::Keyspace, 23 /// Ephemeral cache — currently unused; kept as a home for future read-through caches. 24 #[allow(dead_code)] 25 pub(crate) cache: fjall::Keyspace, 26} 27 28pub type DbRef = Arc<Db>; 29 30/// Open (or create) the fjall database at `path` and return a shared handle. 31pub fn open(path: &Path) -> StorageResult<DbRef> { 32 let database = fjall::Database::builder(path).open()?; 33 let persistent = database.keyspace("persistent", fjall::KeyspaceCreateOptions::default)?; 34 let cache = database.keyspace("cache", fjall::KeyspaceCreateOptions::default)?; 35 Ok(Arc::new(Db { 36 database, 37 persistent, 38 cache, 39 })) 40}