Make sqlx logging configurable for seaorm-rocket (#1192)
This commit is contained in:
parent
9dfc481c3b
commit
9952aa6740
@ -26,7 +26,8 @@ impl sea_orm_rocket::Pool for SeaOrmPool {
|
||||
options
|
||||
.max_connections(config.max_connections as u32)
|
||||
.min_connections(config.min_connections.unwrap_or_default())
|
||||
.connect_timeout(Duration::from_secs(config.connect_timeout));
|
||||
.connect_timeout(Duration::from_secs(config.connect_timeout))
|
||||
.sqlx_logging(config.sqlx_logging);
|
||||
if let Some(idle_timeout) = config.idle_timeout {
|
||||
options.idle_timeout(Duration::from_secs(idle_timeout));
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ use rocket::serde::{Deserialize, Serialize};
|
||||
/// max_connections: 1024,
|
||||
/// connect_timeout: 3,
|
||||
/// idle_timeout: None,
|
||||
/// sqlx_logging: true,
|
||||
/// },
|
||||
/// ));
|
||||
///
|
||||
@ -82,4 +83,7 @@ pub struct Config {
|
||||
///
|
||||
/// _Default:_ `None`.
|
||||
pub idle_timeout: Option<u64>,
|
||||
|
||||
/// Enable SQLx statement logging (default true)
|
||||
pub sqlx_logging: bool,
|
||||
}
|
||||
|
@ -241,7 +241,8 @@ impl<D: Database> Fairing for Initializer<D> {
|
||||
.figment()
|
||||
.focus(&format!("databases.{}", D::NAME))
|
||||
.merge(Serialized::default("max_connections", workers * 4))
|
||||
.merge(Serialized::default("connect_timeout", 5));
|
||||
.merge(Serialized::default("connect_timeout", 5))
|
||||
.merge(Serialized::default("sqlx_logging", true));
|
||||
|
||||
match <D::Pool>::init(&figment).await {
|
||||
Ok(pool) => Ok(rocket.manage(D::from(pool))),
|
||||
|
Loading…
x
Reference in New Issue
Block a user