From 3b15caade07e8fbe351fed9aceb3f435bf58368e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 26 May 2025 18:24:16 +0200 Subject: move all direct database access to logic crate --- logic/src/lib.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'logic/src/lib.rs') 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, admin_username:Option, admin_password:Option, + database_path: PathBuf, } pub static CONF_PRELOAD: Mutex> = Mutex::new(None); @@ -47,3 +52,11 @@ static DATABASE: LazyLock = 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(()) +} -- cgit v1.2.3-70-g09d2