Allow disable SQLx logging
This commit is contained in:
parent
bf595ca926
commit
1d6e6066cd
@ -28,7 +28,7 @@ impl sea_orm_rocket::Pool for SeaOrmPool {
|
||||
if let Some(idle_timeout) = config.idle_timeout {
|
||||
options.idle_timeout(Duration::from_secs(idle_timeout));
|
||||
}
|
||||
let conn = sea_orm::Database::connect(options).await.unwrap();
|
||||
let conn = sea_orm::Database::connect(options).await?;
|
||||
|
||||
Ok(SeaOrmPool { conn })
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ pub struct ConnectOptions {
|
||||
pub(crate) min_connections: Option<u32>,
|
||||
pub(crate) connect_timeout: Option<Duration>,
|
||||
pub(crate) idle_timeout: Option<Duration>,
|
||||
pub(crate) sqlx_logging: bool,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
@ -86,6 +87,7 @@ impl ConnectOptions {
|
||||
min_connections: None,
|
||||
connect_timeout: None,
|
||||
idle_timeout: None,
|
||||
sqlx_logging: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,11 +29,14 @@ impl SqlxMySqlConnector {
|
||||
}
|
||||
|
||||
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
||||
let opt = options
|
||||
let mut opt = options
|
||||
.url
|
||||
.parse::<MySqlConnectOptions>()
|
||||
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
||||
// opt.disable_statement_logging();
|
||||
if !options.sqlx_logging {
|
||||
use sqlx::ConnectOptions;
|
||||
opt.disable_statement_logging();
|
||||
}
|
||||
if let Ok(pool) = options.pool_options().connect_with(opt).await {
|
||||
Ok(DatabaseConnection::SqlxMySqlPoolConnection(
|
||||
SqlxMySqlPoolConnection { pool },
|
||||
|
@ -29,11 +29,14 @@ impl SqlxPostgresConnector {
|
||||
}
|
||||
|
||||
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
||||
let opt = options
|
||||
let mut opt = options
|
||||
.url
|
||||
.parse::<PgConnectOptions>()
|
||||
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
||||
// opt.disable_statement_logging();
|
||||
if !options.sqlx_logging {
|
||||
use sqlx::ConnectOptions;
|
||||
opt.disable_statement_logging();
|
||||
}
|
||||
if let Ok(pool) = options.pool_options().connect_with(opt).await {
|
||||
Ok(DatabaseConnection::SqlxPostgresPoolConnection(
|
||||
SqlxPostgresPoolConnection { pool },
|
||||
|
@ -29,11 +29,14 @@ impl SqlxSqliteConnector {
|
||||
}
|
||||
|
||||
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
||||
let opt = options
|
||||
let mut opt = options
|
||||
.url
|
||||
.parse::<SqliteConnectOptions>()
|
||||
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
||||
// opt.disable_statement_logging();
|
||||
if !options.sqlx_logging {
|
||||
use sqlx::ConnectOptions;
|
||||
opt.disable_statement_logging();
|
||||
}
|
||||
if let Ok(pool) = options
|
||||
.pool_options()
|
||||
.max_connections(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user