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 {
|
if let Some(idle_timeout) = config.idle_timeout {
|
||||||
options.idle_timeout(Duration::from_secs(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 })
|
Ok(SeaOrmPool { conn })
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ pub struct ConnectOptions {
|
|||||||
pub(crate) min_connections: Option<u32>,
|
pub(crate) min_connections: Option<u32>,
|
||||||
pub(crate) connect_timeout: Option<Duration>,
|
pub(crate) connect_timeout: Option<Duration>,
|
||||||
pub(crate) idle_timeout: Option<Duration>,
|
pub(crate) idle_timeout: Option<Duration>,
|
||||||
|
pub(crate) sqlx_logging: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
@ -86,6 +87,7 @@ impl ConnectOptions {
|
|||||||
min_connections: None,
|
min_connections: None,
|
||||||
connect_timeout: None,
|
connect_timeout: None,
|
||||||
idle_timeout: None,
|
idle_timeout: None,
|
||||||
|
sqlx_logging: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,11 +29,14 @@ impl SqlxMySqlConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
||||||
let opt = options
|
let mut opt = options
|
||||||
.url
|
.url
|
||||||
.parse::<MySqlConnectOptions>()
|
.parse::<MySqlConnectOptions>()
|
||||||
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
.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 {
|
if let Ok(pool) = options.pool_options().connect_with(opt).await {
|
||||||
Ok(DatabaseConnection::SqlxMySqlPoolConnection(
|
Ok(DatabaseConnection::SqlxMySqlPoolConnection(
|
||||||
SqlxMySqlPoolConnection { pool },
|
SqlxMySqlPoolConnection { pool },
|
||||||
|
@ -29,11 +29,14 @@ impl SqlxPostgresConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
||||||
let opt = options
|
let mut opt = options
|
||||||
.url
|
.url
|
||||||
.parse::<PgConnectOptions>()
|
.parse::<PgConnectOptions>()
|
||||||
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
.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 {
|
if let Ok(pool) = options.pool_options().connect_with(opt).await {
|
||||||
Ok(DatabaseConnection::SqlxPostgresPoolConnection(
|
Ok(DatabaseConnection::SqlxPostgresPoolConnection(
|
||||||
SqlxPostgresPoolConnection { pool },
|
SqlxPostgresPoolConnection { pool },
|
||||||
|
@ -29,11 +29,14 @@ impl SqlxSqliteConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
pub async fn connect(options: ConnectOptions) -> Result<DatabaseConnection, DbErr> {
|
||||||
let opt = options
|
let mut opt = options
|
||||||
.url
|
.url
|
||||||
.parse::<SqliteConnectOptions>()
|
.parse::<SqliteConnectOptions>()
|
||||||
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
.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
|
if let Ok(pool) = options
|
||||||
.pool_options()
|
.pool_options()
|
||||||
.max_connections(1)
|
.max_connections(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user