diff options
Diffstat (limited to 'logic/src/lib.rs')
-rw-r--r-- | logic/src/lib.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/logic/src/lib.rs b/logic/src/lib.rs index 004e008..9988ed2 100644 --- a/logic/src/lib.rs +++ b/logic/src/lib.rs @@ -6,6 +6,7 @@ #![feature(duration_constructors, let_chains)] pub mod admin; +pub mod assets; pub mod filter_sort; pub mod home; pub mod items; @@ -14,10 +15,13 @@ pub mod node; pub mod search; pub mod session; pub mod stats; +pub mod account; -pub use jellydb::Database; - +use anyhow::Context; +use anyhow::Result; +use jellydb::Database; use serde::{Deserialize, Serialize}; +use std::path::PathBuf; use std::sync::LazyLock; use std::sync::Mutex; @@ -28,6 +32,7 @@ pub struct Config { session_key: Option<String>, admin_username:Option<String>, admin_password:Option<String>, + database_path: PathBuf, } pub static CONF_PRELOAD: Mutex<Option<Config>> = Mutex::new(None); @@ -47,3 +52,11 @@ static DATABASE: LazyLock<Database> = LazyLock::new(|| { .take() .expect("database not preloaded. logic error") }); + +pub fn init_database() -> Result<()> { + let database = Database::open(&CONF.database_path) + .context("opening database") + .unwrap(); + *DATABASE_PRELOAD.lock().unwrap() = Some(database); + Ok(()) +} |