Fix memory db closing
This commit is contained in:
parent
0112e552fd
commit
69e0b87f99
18
src/lib.rs
18
src/lib.rs
|
@ -17,10 +17,10 @@ use sqlx::{
|
||||||
SqlitePool,
|
SqlitePool,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
// #[cfg(not(debug_assertions))]
|
||||||
const MEMORY_URL: &str = "sqlite://:memory:";
|
// const CACHE_URL: &str = "sqlite://:memory:";
|
||||||
#[cfg(debug_assertions)]
|
// #[cfg(debug_assertions)]
|
||||||
const MEMORY_URL: &str = "sqlite://cache.db";
|
const CACHE_URL: &str = "sqlite://cache.db";
|
||||||
|
|
||||||
/// A Sqlite database for all blog data.
|
/// A Sqlite database for all blog data.
|
||||||
///
|
///
|
||||||
|
@ -51,7 +51,7 @@ impl BlogDb {
|
||||||
.await?;
|
.await?;
|
||||||
#[cfg(debug_assertions)]
|
#[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() {
|
if File::open(db_name).is_err() {
|
||||||
let _ = File::create_new(db_name);
|
let _ = File::create_new(db_name);
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@ impl BlogDb {
|
||||||
let memory = SqlitePoolOptions::new()
|
let memory = SqlitePoolOptions::new()
|
||||||
.min_connections(1)
|
.min_connections(1)
|
||||||
.connect_with(
|
.connect_with(
|
||||||
#[cfg(not(debug_assertions))]
|
// #[cfg(not(debug_assertions))]
|
||||||
SqliteConnectOptions::from_str(MEMORY_URL)?.journal_mode(SqliteJournalMode::Memory),
|
// SqliteConnectOptions::from_str(MEMORY_URL)?.journal_mode(SqliteJournalMode::Memory),
|
||||||
#[cfg(debug_assertions)]
|
// #[cfg(debug_assertions)]
|
||||||
SqliteConnectOptions::from_str(MEMORY_URL)?.journal_mode(SqliteJournalMode::Wal),
|
SqliteConnectOptions::from_str(CACHE_URL)?.journal_mode(SqliteJournalMode::Wal),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Self::run_main_migrations(&db).await?;
|
Self::run_main_migrations(&db).await?;
|
||||||
|
|
Loading…
Reference in New Issue