use anyhow::Result; use sqlx::{SqlitePool, sqlite::SqliteConnectOptions}; use std::str::FromStr; pub struct DatabaseConfig { pub database_url: String, } pub async fn create_pool(config: &DatabaseConfig) -> Result { let options = SqliteConnectOptions::from_str(&config.database_url)?.create_if_missing(true); let pool = SqlitePool::connect_with(options).await?; sqlx::migrate!("./migrations").run(&pool).await?; Ok(pool) } #[cfg(test)] pub async fn create_test_pool() -> Result { let options = SqliteConnectOptions::from_str("sqlite::memory:")?.create_if_missing(true); let pool = SqlitePool::connect_with(options).await?; sqlx::migrate!("./migrations").run(&pool).await?; Ok(pool) }