reorganize database crate.

split database Cork into unit.

split database migrations from mod.rs

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-04-06 01:24:08 -07:00 committed by June
parent fe91ce0601
commit 865b5d7241
11 changed files with 849 additions and 811 deletions

32
src/database/cork.rs Normal file
View file

@ -0,0 +1,32 @@
use std::sync::Arc;
use super::KeyValueDatabaseEngine;
pub struct Cork {
db: Arc<dyn KeyValueDatabaseEngine>,
flush: bool,
sync: bool,
}
impl Cork {
pub(crate) fn new(db: &Arc<dyn KeyValueDatabaseEngine>, flush: bool, sync: bool) -> Self {
db.cork().unwrap();
Cork {
db: db.clone(),
flush,
sync,
}
}
}
impl Drop for Cork {
fn drop(&mut self) {
self.db.uncork().ok();
if self.flush {
self.db.flush().ok();
}
if self.sync {
self.db.sync().ok();
}
}
}