diff --git a/src/lib.rs b/src/lib.rs index f5edf7a..b30c09b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,3 +22,11 @@ pub static DIST_DIR: LazyLock = 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 = + LazyLock::new(|| format!("sqlite://{}", CACHE_DIR.join("data").to_str().unwrap())); diff --git a/src/state.rs b/src/state.rs index a7783d2..17e689b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -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"), ), } }