use super::Config; use crate::Result; use std::{future::Future, pin::Pin, sync::Arc}; #[cfg(feature = "rocksdb")] pub mod rocksdb; #[cfg(feature = "sled")] pub mod sled; #[cfg(feature = "sqlite")] pub mod sqlite; pub trait DatabaseEngine: Sized { fn open(config: &Config) -> Result>; fn open_tree(self: &Arc, name: &'static str) -> Result>; fn flush(self: &Arc) -> Result<()>; } pub trait Tree: Send + Sync { fn get(&self, key: &[u8]) -> Result>>; fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>; fn remove(&self, key: &[u8]) -> Result<()>; fn iter<'a>(&'a self) -> Box, Vec)> + Send + 'a>; fn iter_from<'a>( &'a self, from: &[u8], backwards: bool, ) -> Box, Vec)> + Send + 'a>; fn increment(&self, key: &[u8]) -> Result>; fn scan_prefix<'a>( &'a self, prefix: Vec, ) -> Box, Vec)> + Send + '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(()) } }