Create hurl tests along with the necessary api code to resolve them. Reviewed-on: #2 Co-authored-by: Drew Galbraith <drew@tiramisu.one> Co-committed-by: Drew Galbraith <drew@tiramisu.one>
28 lines
752 B
Rust
28 lines
752 B
Rust
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<SqlitePool> {
|
|
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<SqlitePool> {
|
|
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)
|
|
}
|