diff --git a/Cargo.toml b/Cargo.toml index ccbb83fe..643d3e03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,11 @@ utils = { path = "crates/utils" } tokio = { version = "1.23", features = ["full"] } tracing = "0.1" +[features] +default = ["sqlite"] +sqlite = ["store/sqlite"] +foundationdb = ["store/foundation"] + [workspace] members = [ "crates/jmap", diff --git a/crates/store/Cargo.toml b/crates/store/Cargo.toml index f6d1e53d..71441d08 100644 --- a/crates/store/Cargo.toml +++ b/crates/store/Cargo.toml @@ -33,13 +33,11 @@ num_cpus = { version = "1.15.0", optional = true } blake3 = "1.3.3" tracing = "0.1" - [features] -default = ["foundation"] -rocks = ["rocksdb", "rayon", "is_sync"] -sqlite = ["rusqlite", "rayon", "r2d2", "num_cpus", "is_sync"] -foundation = ["foundationdb", "futures", "is_async", "key_subspace"] +rocks = ["rocksdb", "rayon", "is_sync", "backend"] +sqlite = ["rusqlite", "rayon", "r2d2", "num_cpus", "is_sync", "backend"] +foundation = ["foundationdb", "futures", "key_subspace", "backend"] is_sync = ["maybe-async/is_sync", "lru-cache"] -is_async = [] +backend = [] key_subspace = [] test_mode = [] diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index 1557302f..566e6b32 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -78,6 +78,17 @@ pub struct ReadTransaction<'x> { _p: std::marker::PhantomData<&'x ()>, } +#[cfg(not(feature = "backend"))] +#[allow(dead_code)] +pub struct Store { + blob: BlobStore, +} + +#[cfg(not(feature = "backend"))] +pub struct ReadTransaction<'x> { + _db: &'x [u8], +} + pub trait Deserialize: Sized + Sync + Send { fn deserialize(bytes: &[u8]) -> crate::Result; } @@ -218,3 +229,125 @@ pub const SUBSPACE_BITMAPS: u8 = b'b'; pub const SUBSPACE_VALUES: u8 = b'v'; pub const SUBSPACE_LOGS: u8 = b'l'; pub const SUBSPACE_INDEXES: u8 = b'i'; + +#[cfg(not(feature = "backend"))] +impl Store { + pub async fn open(_config: &utils::config::Config) -> crate::Result { + unimplemented!("No backend selected") + } + + pub async fn purge_bitmaps(&self) -> crate::Result<()> { + unimplemented!("No backend selected") + } + + pub async fn purge_account(&self, _account_id: u32) -> crate::Result<()> { + unimplemented!("No backend selected") + } + + pub async fn read_transaction(&self) -> crate::Result> { + unimplemented!("No backend selected") + } + + pub async fn write(&self, _batch: write::Batch) -> crate::Result<()> { + unimplemented!("No backend selected") + } + + pub async fn assign_document_id( + &self, + _account_id: u32, + _collection: impl Into, + ) -> crate::Result { + unimplemented!("No backend selected") + } + + pub async fn assign_change_id(&self, _account_id: u32) -> crate::Result { + unimplemented!("No backend selected") + } + + #[cfg(feature = "test_mode")] + pub async fn destroy(&self) { + unimplemented!("No backend selected") + } + + #[cfg(feature = "test_mode")] + pub async fn assert_is_empty(&self) { + unimplemented!("No backend selected") + } +} + +#[cfg(not(feature = "backend"))] +impl ReadTransaction<'_> { + pub async fn get_value(&self, _key: impl Key) -> crate::Result> + where + U: Deserialize, + { + unimplemented!("No backend selected") + } + + pub async fn get_bitmap>( + &self, + _key: BitmapKey, + ) -> crate::Result> { + unimplemented!("No backend selected") + } + + pub(crate) async fn get_bitmaps_intersection>( + &self, + _keys: Vec>, + ) -> crate::Result> { + unimplemented!("No backend selected") + } + + pub(crate) async fn get_bitmaps_union>( + &self, + _keys: Vec>, + ) -> crate::Result> { + unimplemented!("No backend selected") + } + + pub(crate) async fn range_to_bitmap( + &self, + _account_id: u32, + _collection: u8, + _field: u8, + _value: Vec, + _op: query::Operator, + ) -> crate::Result> { + unimplemented!("No backend selected") + } + + pub(crate) async fn sort_index( + &self, + _account_id: u32, + _collection: u8, + _field: u8, + _ascending: bool, + _cb: impl FnMut(&[u8], u32) -> bool, + ) -> crate::Result<()> { + unimplemented!("No backend selected") + } + + pub(crate) async fn iterate( + &self, + _acc: T, + _begin: impl Key, + _end: impl Key, + _first: bool, + _ascending: bool, + _cb: impl Fn(&mut T, &[u8], &[u8]) -> crate::Result + Sync + Send + 'static, + ) -> crate::Result { + unimplemented!("No backend selected") + } + + pub(crate) async fn get_last_change_id( + &self, + _account_id: u32, + _collection: u8, + ) -> crate::Result> { + unimplemented!("No backend selected") + } + + pub async fn refresh_if_old(&mut self) -> crate::Result<()> { + unimplemented!("No backend selected") + } +} diff --git a/crates/store/src/query/filter.rs b/crates/store/src/query/filter.rs index d5056639..5b74a9ae 100644 --- a/crates/store/src/query/filter.rs +++ b/crates/store/src/query/filter.rs @@ -162,7 +162,7 @@ impl Store { filters: Vec, ) -> crate::Result { let collection = collection.into(); - #[cfg(feature = "is_async")] + #[cfg(not(feature = "is_sync"))] { self.read_transaction() .await? diff --git a/crates/store/src/query/get.rs b/crates/store/src/query/get.rs index c397e789..e6333245 100644 --- a/crates/store/src/query/get.rs +++ b/crates/store/src/query/get.rs @@ -30,7 +30,7 @@ impl Store { where U: Deserialize + 'static, { - #[cfg(feature = "is_async")] + #[cfg(not(feature = "is_sync"))] { self.read_transaction().await?.get_value(key).await } @@ -46,7 +46,7 @@ impl Store { where U: Deserialize + 'static, { - #[cfg(feature = "is_async")] + #[cfg(not(feature = "is_sync"))] { let mut trx = self.read_transaction().await?; let mut results = Vec::with_capacity(key.len()); @@ -81,7 +81,7 @@ impl Store { ) -> crate::Result> { let collection = collection.into(); - #[cfg(feature = "is_async")] + #[cfg(not(feature = "is_sync"))] { self.read_transaction() .await? @@ -101,7 +101,7 @@ impl Store { &self, key: BitmapKey, ) -> crate::Result> { - #[cfg(feature = "is_async")] + #[cfg(not(feature = "is_sync"))] { self.read_transaction().await?.get_bitmap(key).await } @@ -122,7 +122,7 @@ impl Store { ascending: bool, cb: impl Fn(&mut T, &[u8], &[u8]) -> crate::Result + Sync + Send + 'static, ) -> crate::Result { - #[cfg(feature = "is_async")] + #[cfg(not(feature = "is_sync"))] { self.read_transaction() .await? diff --git a/crates/store/src/query/sort.rs b/crates/store/src/query/sort.rs index 572523bf..12fa32e8 100644 --- a/crates/store/src/query/sort.rs +++ b/crates/store/src/query/sort.rs @@ -233,7 +233,7 @@ impl Store { (a, b) => std::cmp::min(a as usize, b), }; - #[cfg(feature = "is_async")] + #[cfg(not(feature = "is_sync"))] { self.read_transaction() .await? diff --git a/tests/Cargo.toml b/tests/Cargo.toml index e6aee54d..ca980858 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -4,6 +4,11 @@ version = "0.1.0" edition = "2021" resolver = "2" +[features] +default = ["sqlite"] +sqlite = ["store/sqlite"] +foundationdb = ["store/foundation"] + [dev-dependencies] store = { path = "../crates/store", features = ["test_mode"] } jmap = { path = "../crates/jmap", features = ["test_mode"] } diff --git a/tests/src/store/assign_id.rs b/tests/src/store/assign_id.rs index eed81298..c1b13b3c 100644 --- a/tests/src/store/assign_id.rs +++ b/tests/src/store/assign_id.rs @@ -30,16 +30,16 @@ use store::{write::BatchBuilder, Store}; pub async fn test(db: Arc) { println!("Running Store ID assignment tests..."); - store::backend::foundationdb::write::ID_ASSIGNMENT_EXPIRY - .store(2, std::sync::atomic::Ordering::Relaxed); + /*store::backend::foundationdb::write::ID_ASSIGNMENT_EXPIRY + .store(2, std::sync::atomic::Ordering::Relaxed);*/ test_1(db.clone()).await; test_2(db.clone()).await; test_3(db.clone()).await; test_4(db).await; - store::backend::foundationdb::write::ID_ASSIGNMENT_EXPIRY - .store(60 * 60, std::sync::atomic::Ordering::Relaxed); + /*store::backend::foundationdb::write::ID_ASSIGNMENT_EXPIRY + .store(60 * 60, std::sync::atomic::Ordering::Relaxed);*/ } async fn test_1(db: Arc) {