From 9952aa6740ea482590351cebd59bc44f9c76f645 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sun, 6 Nov 2022 05:03:07 +0100 Subject: [PATCH] Make sqlx logging configurable for seaorm-rocket (#1192) --- examples/rocket_example/api/src/pool.rs | 3 ++- sea-orm-rocket/lib/src/config.rs | 4 ++++ sea-orm-rocket/lib/src/database.rs | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/rocket_example/api/src/pool.rs b/examples/rocket_example/api/src/pool.rs index b1c056779..da8470ace 100644 --- a/examples/rocket_example/api/src/pool.rs +++ b/examples/rocket_example/api/src/pool.rs @@ -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)); } diff --git a/sea-orm-rocket/lib/src/config.rs b/sea-orm-rocket/lib/src/config.rs index 4a48aa399..2f29f2bbf 100644 --- a/sea-orm-rocket/lib/src/config.rs +++ b/sea-orm-rocket/lib/src/config.rs @@ -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, + + /// Enable SQLx statement logging (default true) + pub sqlx_logging: bool, } diff --git a/sea-orm-rocket/lib/src/database.rs b/sea-orm-rocket/lib/src/database.rs index 437926725..ead6710da 100644 --- a/sea-orm-rocket/lib/src/database.rs +++ b/sea-orm-rocket/lib/src/database.rs @@ -241,7 +241,8 @@ impl Fairing for Initializer { .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 ::init(&figment).await { Ok(pool) => Ok(rocket.manage(D::from(pool))),