Conduit is a simple, fast and reliable chat server powered by Matrix https://conduit.rs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
57 lines
1.5 KiB
use super::Config; |
|
use crate::Result; |
|
|
|
use std::{future::Future, pin::Pin, sync::Arc}; |
|
|
|
#[cfg(feature = "sled")] |
|
pub mod sled; |
|
|
|
#[cfg(feature = "sqlite")] |
|
pub mod sqlite; |
|
|
|
#[cfg(feature = "heed")] |
|
pub mod heed; |
|
|
|
#[cfg(feature = "persy")] |
|
pub mod persy; |
|
|
|
pub trait DatabaseEngine: Sized { |
|
fn open(config: &Config) -> Result<Arc<Self>>; |
|
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>>; |
|
fn flush(self: &Arc<Self>) -> Result<()>; |
|
} |
|
|
|
pub trait Tree: Send + Sync { |
|
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>; |
|
|
|
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>; |
|
fn insert_batch(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<()>; |
|
|
|
fn remove(&self, key: &[u8]) -> Result<()>; |
|
|
|
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>; |
|
|
|
fn iter_from<'a>( |
|
&'a self, |
|
from: &[u8], |
|
backwards: bool, |
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>; |
|
|
|
fn increment(&self, key: &[u8]) -> Result<Vec<u8>>; |
|
fn increment_batch(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()>; |
|
|
|
fn scan_prefix<'a>( |
|
&'a self, |
|
prefix: Vec<u8>, |
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>; |
|
|
|
fn watch_prefix<'a>(&'a self, prefix: &[u8]) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>>; |
|
|
|
fn clear(&self) -> Result<()> { |
|
for (key, _) in self.iter() { |
|
self.remove(&key)?; |
|
} |
|
|
|
Ok(()) |
|
} |
|
}
|
|
|