fix: changes to update to the last database engine trait definition

This commit is contained in:
Tglman 2022-01-13 22:37:19 +00:00
parent 1cc41937bd
commit f9977ca64f
2 changed files with 12 additions and 7 deletions

View file

@ -18,7 +18,12 @@ pub mod rocksdb;
#[cfg(feature = "persy")] #[cfg(feature = "persy")]
pub mod persy; pub mod persy;
#[cfg(any(feature = "sqlite", feature = "rocksdb", feature = "heed", feature="persy"))] #[cfg(any(
feature = "sqlite",
feature = "rocksdb",
feature = "heed",
feature = "persy"
))]
pub mod watchers; pub mod watchers;
pub trait DatabaseEngine: Send + Sync { pub trait DatabaseEngine: Send + Sync {

View file

@ -11,12 +11,12 @@ use std::{future::Future, pin::Pin, sync::Arc};
use tracing::warn; use tracing::warn;
pub struct PersyEngine { pub struct Engine {
persy: Persy, persy: Persy,
} }
impl DatabaseEngine for PersyEngine { impl DatabaseEngine for Arc<Engine> {
fn open(config: &Config) -> Result<Arc<Self>> { fn open(config: &Config) -> Result<Self> {
let mut cfg = persy::Config::new(); let mut cfg = persy::Config::new();
cfg.change_cache_size((config.db_cache_capacity_mb * 1024.0 * 1024.0) as u64); cfg.change_cache_size((config.db_cache_capacity_mb * 1024.0 * 1024.0) as u64);
@ -24,10 +24,10 @@ impl DatabaseEngine for PersyEngine {
.create(true) .create(true)
.config(cfg) .config(cfg)
.open(&format!("{}/db.persy", config.database_path))?; .open(&format!("{}/db.persy", config.database_path))?;
Ok(Arc::new(PersyEngine { persy })) Ok(Arc::new(Engine { persy }))
} }
fn open_tree(self: &Arc<Self>, name: &'static str) -> Result<Arc<dyn Tree>> { fn open_tree(&self, name: &'static str) -> Result<Arc<dyn Tree>> {
// Create if it doesn't exist // Create if it doesn't exist
if !self.persy.exists_index(name)? { if !self.persy.exists_index(name)? {
let mut tx = self.persy.begin()?; let mut tx = self.persy.begin()?;
@ -42,7 +42,7 @@ impl DatabaseEngine for PersyEngine {
})) }))
} }
fn flush(self: &Arc<Self>) -> Result<()> { fn flush(&self) -> Result<()> {
Ok(()) Ok(())
} }
} }