tracing
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use std::time;
|
||||
|
||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
||||
use sqlx::ConnectOptions;
|
||||
pub use sqlx::{Pool, Sqlite};
|
||||
|
||||
use std::str::FromStr as _;
|
||||
@@ -8,14 +11,23 @@ use crate::StartError;
|
||||
pub async fn init_database_pool(url: &str) -> Result<Pool<Sqlite>, StartError> {
|
||||
Ok(SqlitePoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect_with(SqliteConnectOptions::from_str(url)?.pragma("foreign_keys", "1"))
|
||||
.connect_with(
|
||||
SqliteConnectOptions::from_str(url)?
|
||||
.log_statements(log::LevelFilter::Off)
|
||||
.log_slow_statements(log::LevelFilter::Warn, time::Duration::from_millis(100))
|
||||
.pragma("foreign_keys", "1"),
|
||||
)
|
||||
.await?)
|
||||
}
|
||||
|
||||
pub async fn migrate(url: &str) -> Result<(), StartError> {
|
||||
let pool = SqlitePoolOptions::new()
|
||||
.max_connections(5)
|
||||
.connect_with(SqliteConnectOptions::from_str(url)?.pragma("foreign_keys", "0"))
|
||||
.connect_with(
|
||||
SqliteConnectOptions::from_str(url)?
|
||||
.pragma("foreign_keys", "0")
|
||||
.log_statements(log::LevelFilter::Off),
|
||||
)
|
||||
.await?;
|
||||
|
||||
sqlx::migrate!().run(&pool).await?;
|
||||
|
||||
Reference in New Issue
Block a user