feat: define DB_URL relative to CACHE_DIR

This commit is contained in:
Zynh Ludwig 2025-01-12 19:14:25 -08:00
parent 11011d1423
commit 17d194e75b
2 changed files with 11 additions and 2 deletions

View file

@ -22,3 +22,11 @@ pub static DIST_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from("./dist"))
});
// This could utilize and env var like the others, but for now i have chosen to ignore it
//
// pros: would match dev environment and sqlx-cli better
// cons: don't feel like it right now
//
// FIXME: better errors here
pub static DB_URL: LazyLock<String> =
LazyLock::new(|| format!("sqlite://{}", CACHE_DIR.join("data").to_str().unwrap()));

View file

@ -2,6 +2,8 @@ use std::str::FromStr;
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
use crate::DB_URL;
#[derive(Clone)]
pub struct AppState {
pub pool: SqlitePool,
@ -11,8 +13,7 @@ impl AppState {
pub fn new() -> Self {
Self {
pool: SqlitePool::connect_lazy_with(
SqliteConnectOptions::from_str("sqlite://.cache/data")
.expect("Invalid Database String"),
SqliteConnectOptions::from_str(&DB_URL).expect("Invalid Database String"),
),
}
}