mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 07:02:24 +00:00
Outsource db pool creation in preparation for unit tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use sqlx::SqlitePool;
|
||||
use sqlx::{sqlite::SqliteConnectOptions, Pool, Sqlite, SqlitePool};
|
||||
|
||||
use crate::{
|
||||
calendar::{Calendar, CalendarStore},
|
||||
@@ -111,3 +111,17 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_db_pool(db_url: &str, migrate: bool) -> anyhow::Result<Pool<Sqlite>>{
|
||||
let db = SqlitePool::connect_with(
|
||||
SqliteConnectOptions::new()
|
||||
.filename(db_url)
|
||||
.create_if_missing(true),
|
||||
)
|
||||
.await?;
|
||||
if migrate {
|
||||
println!("Running database migrations");
|
||||
sqlx::migrate!("./migrations").run(&db).await?;
|
||||
}
|
||||
Ok(db)
|
||||
}
|
||||
Reference in New Issue
Block a user