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( let db = SqlitePool::connect_with(
SqliteConnectOptions::new() SqliteConnectOptions::new()
.filename(db_url) .filename(db_url)
@@ -125,3 +125,9 @@ pub async fn create_db_pool(db_url: &str, migrate: bool) -> anyhow::Result<Pool<
} }
Ok(db) 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))
}