diff options
author | Adam T. Carpenter <atc@53hor.net> | 2021-04-09 18:50:55 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2021-04-09 18:50:55 -0400 |
commit | 201a37e8d3d0ef4c59b184c0707ec8ddd301a25a (patch) | |
tree | 1aae6c03bfb9f694adea81510dacf586311fcc12 /src/repo | |
parent | 881e4bf3c9141b4bebaefaf6385652ed46d9a9fe (diff) | |
download | twinh-201a37e8d3d0ef4c59b184c0707ec8ddd301a25a.tar.xz twinh-201a37e8d3d0ef4c59b184c0707ec8ddd301a25a.zip |
spruced up templates, some repo impl
Diffstat (limited to 'src/repo')
-rw-r--r-- | src/repo/constants.rs | 9 | ||||
-rw-r--r-- | src/repo/mod.rs | 28 |
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(()) } |