summaryrefslogtreecommitdiff
path: root/src/repo
diff options
context:
space:
mode:
Diffstat (limited to 'src/repo')
-rw-r--r--src/repo/constants.rs9
-rw-r--r--src/repo/mod.rs28
2 files changed, 24 insertions, 13 deletions
diff --git a/src/repo/constants.rs b/src/repo/constants.rs
index e168a77..6da641f 100644
--- a/src/repo/constants.rs
+++ b/src/repo/constants.rs
@@ -1,11 +1,2 @@
-use once_cell::sync::Lazy;
-use sled::{Config, Db};
-
pub const PARTS_TREE: &str = "parts";
pub const CARS_TREE: &str = "cars";
-pub static REPO_INSTANCE: Lazy<Db> = Lazy::new(|| {
- Config::default()
- .path("/tmp/twinh")
- .open()
- .expect("Couldn't open DB!")
-});
diff --git a/src/repo/mod.rs b/src/repo/mod.rs
index d4c5e44..f0bb95c 100644
--- a/src/repo/mod.rs
+++ b/src/repo/mod.rs
@@ -1,16 +1,36 @@
+use crate::config::CONFIG_INSTANCE;
use crate::error::TwinHError;
use crate::models::Car;
use crate::models::Part;
use bincode::deserialize;
use constants::*;
+use once_cell::sync::Lazy;
+use sled::{Config, Db};
mod constants;
+static REPO_INSTANCE: Lazy<Db> = Lazy::new(|| {
+ Config::default()
+ .path(&CONFIG_INSTANCE.db_uri)
+ .temporary(true)
+ .open()
+ .expect("Couldn't open DB!")
+});
+
+pub fn create_demo_db() -> Result<(), TwinHError> {
+ let db = sled::Config::default()
+ .path(&CONFIG_INSTANCE.db_uri)
+ .create_new(true)
+ .open()?;
+ let cars_tree = db.open_tree(CARS_TREE)?;
+ Ok(())
+}
+
pub fn create_new_db() -> Result<(), TwinHError> {
- let config = sled::Config::default()
- .path("/var/db/twinh")
- .create_new(true);
- let db = config.open()?;
+ sled::Config::default()
+ .path(&CONFIG_INSTANCE.db_uri)
+ .create_new(true)
+ .open()?;
Ok(())
}