Fix memory db closing

This commit is contained in:
august kline 2024-11-14 11:16:59 -05:00
parent 0112e552fd
commit 69e0b87f99
1 changed files with 9 additions and 9 deletions

View File

@ -17,10 +17,10 @@ use sqlx::{
SqlitePool,
};
#[cfg(not(debug_assertions))]
const MEMORY_URL: &str = "sqlite://:memory:";
#[cfg(debug_assertions)]
const MEMORY_URL: &str = "sqlite://cache.db";
// #[cfg(not(debug_assertions))]
// const CACHE_URL: &str = "sqlite://:memory:";
// #[cfg(debug_assertions)]
const CACHE_URL: &str = "sqlite://cache.db";
/// A Sqlite database for all blog data.
///
@ -51,7 +51,7 @@ impl BlogDb {
.await?;
#[cfg(debug_assertions)]
{
let db_name = MEMORY_URL.strip_prefix("sqlite://").unwrap();
let db_name = CACHE_URL.strip_prefix("sqlite://").unwrap();
if File::open(db_name).is_err() {
let _ = File::create_new(db_name);
}
@ -59,10 +59,10 @@ impl BlogDb {
let memory = SqlitePoolOptions::new()
.min_connections(1)
.connect_with(
#[cfg(not(debug_assertions))]
SqliteConnectOptions::from_str(MEMORY_URL)?.journal_mode(SqliteJournalMode::Memory),
#[cfg(debug_assertions)]
SqliteConnectOptions::from_str(MEMORY_URL)?.journal_mode(SqliteJournalMode::Wal),
// #[cfg(not(debug_assertions))]
// SqliteConnectOptions::from_str(MEMORY_URL)?.journal_mode(SqliteJournalMode::Memory),
// #[cfg(debug_assertions)]
SqliteConnectOptions::from_str(CACHE_URL)?.journal_mode(SqliteJournalMode::Wal),
)
.await?;
Self::run_main_migrations(&db).await?;