Skip to content

Commit

Permalink
Make sqlx logging configurable for seaorm-rocket (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayay authored Nov 6, 2022
1 parent 9dfc481 commit 9952aa6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/rocket_example/api/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 4 additions & 0 deletions sea-orm-rocket/lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use rocket::serde::{Deserialize, Serialize};
/// max_connections: 1024,
/// connect_timeout: 3,
/// idle_timeout: None,
/// sqlx_logging: true,
/// },
/// ));
///
Expand Down Expand Up @@ -82,4 +83,7 @@ pub struct Config {
///
/// _Default:_ `None`.
pub idle_timeout: Option<u64>,

/// Enable SQLx statement logging (default true)
pub sqlx_logging: bool,
}
3 changes: 2 additions & 1 deletion sea-orm-rocket/lib/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down

0 comments on commit 9952aa6

Please sign in to comment.