feat: define DB_URL relative to CACHE_DIR
This commit is contained in:
parent
11011d1423
commit
17d194e75b
2 changed files with 11 additions and 2 deletions
|
@ -22,3 +22,11 @@ pub static DIST_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.unwrap_or_else(|| PathBuf::from("./dist"))
|
.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()));
|
||||||
|
|
|
@ -2,6 +2,8 @@ use std::str::FromStr;
|
||||||
|
|
||||||
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
|
use sqlx::{sqlite::SqliteConnectOptions, SqlitePool};
|
||||||
|
|
||||||
|
use crate::DB_URL;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub pool: SqlitePool,
|
pub pool: SqlitePool,
|
||||||
|
@ -11,8 +13,7 @@ impl AppState {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
pool: SqlitePool::connect_lazy_with(
|
pool: SqlitePool::connect_lazy_with(
|
||||||
SqliteConnectOptions::from_str("sqlite://.cache/data")
|
SqliteConnectOptions::from_str(&DB_URL).expect("Invalid Database String"),
|
||||||
.expect("Invalid Database String"),
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue