diff options
Diffstat (limited to 'src/repo')
-rw-r--r-- | src/repo/mod.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/repo/mod.rs b/src/repo/mod.rs index c7992c9..80b2814 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -1,32 +1,23 @@ +use crate::config; 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}; -use std::env; mod constants; -pub static DB_PATH_INSTANCE: Lazy<String> = Lazy::new(|| { - env::args() - .skip(1) - .last() - .expect("database directory not provided") -}); - -static REPO_INSTANCE: Lazy<Db> = - Lazy::new( - || match Config::default().path(DB_PATH_INSTANCE.as_str()).open() { - Err(e) => panic!("failed to open database: {}", e), - Ok(db) => db, - }, - ); +lazy_static! { + static ref REPO_INSTANCE: Db = match Config::default().path(&config::INSTANCE.data_dir).open() { + Err(e) => panic!("failed to open database: {}", e), + Ok(db) => db, + }; +} pub fn create_demo_db() -> Result<(), TwinHError> { let db = sled::Config::default() - .path(DB_PATH_INSTANCE.as_str()) + .path(&config::INSTANCE.data_dir) .create_new(true) .open()?; let cars_tree = db.open_tree(CARS_TREE)?; @@ -35,7 +26,7 @@ pub fn create_demo_db() -> Result<(), TwinHError> { pub fn create_new_db() -> Result<(), TwinHError> { sled::Config::default() - .path(DB_PATH_INSTANCE.as_str()) + .path(&config::INSTANCE.data_dir) .create_new(true) .open()?; Ok(()) |