aboutsummaryrefslogtreecommitdiff
path: root/logic/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-05-26 18:24:16 +0200
committermetamuffin <metamuffin@disroot.org>2025-05-26 18:24:16 +0200
commit3b15caade07e8fbe351fed9aceb3f435bf58368e (patch)
treecce91c229b78061ad36f29d76a76d67c3c737c59 /logic/src/lib.rs
parent1eeff5c03e8985d16d4f2b6283741dd82b369bd3 (diff)
downloadjellything-3b15caade07e8fbe351fed9aceb3f435bf58368e.tar
jellything-3b15caade07e8fbe351fed9aceb3f435bf58368e.tar.bz2
jellything-3b15caade07e8fbe351fed9aceb3f435bf58368e.tar.zst
move all direct database access to logic crate
Diffstat (limited to 'logic/src/lib.rs')
-rw-r--r--logic/src/lib.rs17
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(())
+}