minauthator/lib/kernel/src/database.rs

22 lines
620 B
Rust
Raw Permalink Normal View History

2024-11-12 14:29:27 +01:00
use anyhow::{Context, Result};
use sqlx::{sqlite::{SqliteConnectOptions, SqlitePoolOptions}, ConnectOptions};
2024-10-15 12:10:46 +02:00
use std::str::FromStr;
use crate::repositories::storage::Storage;
pub async fn prepare_database(sqlite_db_path: &str) -> Result<Storage> {
2024-10-15 12:10:46 +02:00
let conn_str = format!("sqlite:{}", sqlite_db_path);
let pool = SqlitePoolOptions::new()
.max_connections(50)
.connect_with(
SqliteConnectOptions::from_str(&conn_str)?
.log_statements(log::LevelFilter::Trace)
)
.await
.context("could not connect to database_url")?;
Ok(Storage(pool))
2024-10-15 12:10:46 +02:00
}