2021-06-08 17:10:00 +01:00
|
|
|
use super::Config;
|
2021-07-14 08:07:08 +01:00
|
|
|
use crate::Result;
|
|
|
|
|
2021-06-12 14:04:28 +01:00
|
|
|
use std::{future::Future, pin::Pin, sync::Arc};
|
|
|
|
|
|
|
|
#[cfg(feature = "sled")]
|
2021-07-14 08:07:08 +01:00
|
|
|
pub mod sled;
|
2021-06-12 14:04:28 +01:00
|
|
|
|
2021-07-14 08:07:08 +01:00
|
|
|
#[cfg(feature = "sqlite")]
|
|
|
|
pub mod sqlite;
|
2021-06-08 17:10:00 +01:00
|
|
|
|
2021-07-29 19:17:47 +01:00
|
|
|
#[cfg(feature = "heed")]
|
|
|
|
pub mod heed;
|
|
|
|
|
2021-06-08 17:10:00 +01:00
|
|
|
pub trait DatabaseEngine: Sized {
|
|
|
|
fn open(config: &Config) -> Result<Arc<Self>>;
|
|
|
|
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>>;
|
2021-07-14 08:07:08 +01:00
|
|
|
fn flush(self: &Arc<Self>) -> Result<()>;
|
2021-06-08 17:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Tree: Send + Sync {
|
|
|
|
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
|
|
|
|
|
|
|
|
fn insert(&self, key: &[u8], value: &[u8]) -> Result<()>;
|
2021-10-13 09:24:39 +01:00
|
|
|
fn insert_batch(&self, iter: &mut dyn Iterator<Item = (Vec<u8>, Vec<u8>)>) -> Result<()>;
|
2021-06-08 17:10:00 +01:00
|
|
|
|
|
|
|
fn remove(&self, key: &[u8]) -> Result<()>;
|
|
|
|
|
2021-08-02 09:13:34 +01:00
|
|
|
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
|
2021-06-08 17:10:00 +01:00
|
|
|
|
|
|
|
fn iter_from<'a>(
|
|
|
|
&'a self,
|
|
|
|
from: &[u8],
|
|
|
|
backwards: bool,
|
2021-08-02 09:13:34 +01:00
|
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
|
2021-06-08 17:10:00 +01:00
|
|
|
|
|
|
|
fn increment(&self, key: &[u8]) -> Result<Vec<u8>>;
|
2021-10-13 09:24:39 +01:00
|
|
|
fn increment_batch(&self, iter: &mut dyn Iterator<Item = Vec<u8>>) -> Result<()>;
|
2021-06-08 17:10:00 +01:00
|
|
|
|
|
|
|
fn scan_prefix<'a>(
|
|
|
|
&'a self,
|
|
|
|
prefix: Vec<u8>,
|
2021-08-02 09:13:34 +01:00
|
|
|
) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>;
|
2021-06-08 17:10:00 +01:00
|
|
|
|
|
|
|
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(())
|
|
|
|
}
|
|
|
|
}
|