logging
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::queries;
|
||||
use sqlx::{any::AnyPoolOptions, AnyPool};
|
||||
use tracing::{debug, info};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum DatabaseKind {
|
||||
@@ -18,15 +19,18 @@ impl Database {
|
||||
pub async fn connect(url: &str, max_connections: u32) -> Result<Self, sqlx::Error> {
|
||||
sqlx::any::install_default_drivers();
|
||||
let kind = DatabaseKind::from_url(url)?;
|
||||
debug!(?kind, max_connections, "initializing database pool");
|
||||
let pool = AnyPoolOptions::new()
|
||||
.max_connections(max_connections)
|
||||
.connect(url)
|
||||
.await?;
|
||||
if kind == DatabaseKind::Sqlite {
|
||||
debug!("applying SQLite connection pragmas");
|
||||
sqlx::query(queries::SQLITE_FOREIGN_KEYS_ON).execute(&pool).await?;
|
||||
sqlx::query(queries::SQLITE_JOURNAL_WAL).execute(&pool).await?;
|
||||
sqlx::query(queries::SQLITE_BUSY_TIMEOUT).execute(&pool).await?;
|
||||
}
|
||||
info!(?kind, max_connections, "database pool ready");
|
||||
Ok(Self { pool, kind })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user