use std::{future::Future, pin::Pin, sync::Arc}; use super::Config; use crate::Result; #[cfg(feature = "sqlite")] pub mod sqlite; #[cfg(feature = "rocksdb")] pub(crate) mod rocksdb; #[cfg(any(feature = "sqlite", feature = "rocksdb"))] pub(crate) mod watchers; pub(crate) trait KeyValueDatabaseEngine: Send + Sync { fn open(config: &Config) -> Result where Self: Sized; fn open_tree(&self, name: &'static str) -> Result>; fn flush(&self) -> Result<()>; fn cleanup(&self) -> Result<()> { Ok(()) } fn memory_usage(&self) -> Result { Ok("Current database engine does not support memory usage reporting.".to_owned()) } #[allow(dead_code)] fn clear_caches(&self) {} } pub(crate) trait KvTree: Send + Sync { fn get(&self, key: &[u8]) -> Result>>; #[allow(dead_code)] #[cfg(feature = "rocksdb")] fn multi_get( &self, _iter: Vec<(&Arc>, Vec)>, ) -> Vec>, rust_rocksdb::Error>> { unimplemented!() } fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>; fn insert_batch(&self, iter: &mut dyn Iterator, Vec)>) -> Result<()>; fn remove(&self, key: &[u8]) -> Result<()>; #[allow(dead_code)] #[cfg(feature = "rocksdb")] fn remove_batch(&self, _iter: &mut dyn Iterator>) -> Result<()> { unimplemented!() } fn iter<'a>(&'a self) -> Box, Vec)> + 'a>; fn iter_from<'a>(&'a self, from: &[u8], backwards: bool) -> Box, Vec)> + 'a>; fn increment(&self, key: &[u8]) -> Result>; fn increment_batch(&self, iter: &mut dyn Iterator>) -> Result<()>; fn scan_prefix<'a>(&'a self, prefix: Vec) -> Box, Vec)> + 'a>; fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin + Send + 'a>>; fn clear(&self) -> Result<()> { for (key, _) in self.iter() { self.remove(&key)?; } Ok(()) } }