sqlite: constructor for testing store

This commit is contained in:
Lennart
2024-02-26 16:30:08 +01:00
parent 92102ebfc0
commit f8ba0c3600

View File

@@ -112,7 +112,7 @@ impl CalendarStore for SqliteCalendarStore {
}
}
pub async fn create_db_pool(db_url: &str, migrate: bool) -> anyhow::Result<Pool<Sqlite>>{
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)
@@ -124,4 +124,10 @@ pub async fn create_db_pool(db_url: &str, migrate: bool) -> anyhow::Result<Pool<
sqlx::migrate!("./migrations").run(&db).await?;
}
Ok(db)
}
}
pub async fn create_test_store() -> anyhow::Result<SqliteCalendarStore> {
let db = SqlitePool::connect("sqlite::memory:").await?;
sqlx::migrate!("./migrations").run(&db).await?;
Ok(SqliteCalendarStore::new(db))
}