simplify DB constructor

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet
2025-04-25 14:15:52 +02:00
parent b8e1449ddb
commit d8b40b6995
5 changed files with 21 additions and 455 deletions

View File

@@ -3,7 +3,6 @@ use std::borrow::Borrow;
use heromodels_core::{Index, Model};
use serde::{Deserialize, Serialize};
pub mod fjall;
pub mod hero;
pub trait Db {

View File

@@ -5,6 +5,7 @@ use serde::Deserialize;
use std::{
borrow::Borrow,
collections::HashSet,
path::PathBuf,
sync::{Arc, Mutex},
};
@@ -18,11 +19,24 @@ pub struct OurDB {
impl OurDB {
/// Create a new instance of ourdb
pub fn new(index_db: tst::TST, data_db: ourdb::OurDB) -> Self {
Self {
pub fn new(path: impl Into<PathBuf>, reset: bool) -> Result<Self, tst::Error> {
let mut base_path = path.into();
let mut data_path = base_path.clone();
base_path.push("index");
data_path.push("data");
let data_db = ourdb::OurDB::new(ourdb::OurDBConfig {
incremental_mode: false,
path: data_path,
file_size: None,
keysize: None,
reset: Some(reset),
})?;
let index_db = tst::TST::new(base_path.to_str().expect("Path is valid UTF-8"), reset)?;
Ok(OurDB {
index: Arc::new(Mutex::new(index_db)),
data: Arc::new(Mutex::new(data_db)),
}
})
}
}