sqlx_logging_level
, a wrapper around sqlx::ConnectOptions::log_statements
(#800)
* sqlx_logging_level * ` = { version = "..." }`
This commit is contained in:
parent
12ec00272c
commit
4f26b4a585
@ -29,6 +29,7 @@ time = { version = "^0.2", optional = true }
|
|||||||
futures = { version = "^0.3" }
|
futures = { version = "^0.3" }
|
||||||
futures-util = { version = "^0.3" }
|
futures-util = { version = "^0.3" }
|
||||||
tracing = { version = "0.1", features = ["log"] }
|
tracing = { version = "0.1", features = ["log"] }
|
||||||
|
log = { version = "^0"}
|
||||||
rust_decimal = { version = "^1", optional = true }
|
rust_decimal = { version = "^1", optional = true }
|
||||||
sea-orm-macros = { version = "^0.8.0", path = "sea-orm-macros", optional = true }
|
sea-orm-macros = { version = "^0.8.0", path = "sea-orm-macros", optional = true }
|
||||||
sea-query = { version = "^0.24.5", features = ["thread-safe"] }
|
sea-query = { version = "^0.24.5", features = ["thread-safe"] }
|
||||||
|
@ -42,6 +42,8 @@ pub struct ConnectOptions {
|
|||||||
pub(crate) max_lifetime: Option<Duration>,
|
pub(crate) max_lifetime: Option<Duration>,
|
||||||
/// Enable SQLx statement logging
|
/// Enable SQLx statement logging
|
||||||
pub(crate) sqlx_logging: bool,
|
pub(crate) sqlx_logging: bool,
|
||||||
|
/// SQLx statement logging level (ignored if `sqlx_logging` is false)
|
||||||
|
pub(crate) sqlx_logging_level: log::LevelFilter,
|
||||||
/// set sqlcipher key
|
/// set sqlcipher key
|
||||||
pub(crate) sqlcipher_key: Option<Cow<'static, str>>,
|
pub(crate) sqlcipher_key: Option<Cow<'static, str>>,
|
||||||
}
|
}
|
||||||
@ -107,6 +109,7 @@ impl ConnectOptions {
|
|||||||
idle_timeout: None,
|
idle_timeout: None,
|
||||||
max_lifetime: None,
|
max_lifetime: None,
|
||||||
sqlx_logging: true,
|
sqlx_logging: true,
|
||||||
|
sqlx_logging_level: log::LevelFilter::Info,
|
||||||
sqlcipher_key: None,
|
sqlcipher_key: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,6 +214,18 @@ impl ConnectOptions {
|
|||||||
self.sqlx_logging
|
self.sqlx_logging
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set SQLx statement logging level (default INFO)
|
||||||
|
/// (ignored if `sqlx_logging` is `false`)
|
||||||
|
pub fn sqlx_logging_level(&mut self, level: log::LevelFilter) -> &mut Self {
|
||||||
|
self.sqlx_logging_level = level;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the level of SQLx statement logging
|
||||||
|
pub fn get_sqlx_logging_level(&self) -> log::LevelFilter {
|
||||||
|
self.sqlx_logging_level
|
||||||
|
}
|
||||||
|
|
||||||
/// set key for sqlcipher
|
/// set key for sqlcipher
|
||||||
pub fn sqlcipher_key<T>(&mut self, value: T) -> &mut Self
|
pub fn sqlcipher_key<T>(&mut self, value: T) -> &mut Self
|
||||||
where
|
where
|
||||||
|
@ -46,9 +46,11 @@ impl SqlxMySqlConnector {
|
|||||||
.url
|
.url
|
||||||
.parse::<MySqlConnectOptions>()
|
.parse::<MySqlConnectOptions>()
|
||||||
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
||||||
if !options.sqlx_logging {
|
|
||||||
use sqlx::ConnectOptions;
|
use sqlx::ConnectOptions;
|
||||||
|
if !options.sqlx_logging {
|
||||||
opt.disable_statement_logging();
|
opt.disable_statement_logging();
|
||||||
|
} else {
|
||||||
|
opt.log_statements(options.sqlx_logging_level);
|
||||||
}
|
}
|
||||||
match options.pool_options().connect_with(opt).await {
|
match options.pool_options().connect_with(opt).await {
|
||||||
Ok(pool) => Ok(DatabaseConnection::SqlxMySqlPoolConnection(
|
Ok(pool) => Ok(DatabaseConnection::SqlxMySqlPoolConnection(
|
||||||
|
@ -46,9 +46,11 @@ impl SqlxPostgresConnector {
|
|||||||
.url
|
.url
|
||||||
.parse::<PgConnectOptions>()
|
.parse::<PgConnectOptions>()
|
||||||
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
.map_err(|e| DbErr::Conn(e.to_string()))?;
|
||||||
if !options.sqlx_logging {
|
|
||||||
use sqlx::ConnectOptions;
|
use sqlx::ConnectOptions;
|
||||||
|
if !options.sqlx_logging {
|
||||||
opt.disable_statement_logging();
|
opt.disable_statement_logging();
|
||||||
|
} else {
|
||||||
|
opt.log_statements(options.sqlx_logging_level);
|
||||||
}
|
}
|
||||||
match options.pool_options().connect_with(opt).await {
|
match options.pool_options().connect_with(opt).await {
|
||||||
Ok(pool) => Ok(DatabaseConnection::SqlxPostgresPoolConnection(
|
Ok(pool) => Ok(DatabaseConnection::SqlxPostgresPoolConnection(
|
||||||
|
@ -50,9 +50,11 @@ impl SqlxSqliteConnector {
|
|||||||
if options.sqlcipher_key.is_some() {
|
if options.sqlcipher_key.is_some() {
|
||||||
opt = opt.pragma("key", options.sqlcipher_key.clone().unwrap());
|
opt = opt.pragma("key", options.sqlcipher_key.clone().unwrap());
|
||||||
}
|
}
|
||||||
if !options.sqlx_logging {
|
|
||||||
use sqlx::ConnectOptions;
|
use sqlx::ConnectOptions;
|
||||||
|
if !options.sqlx_logging {
|
||||||
opt.disable_statement_logging();
|
opt.disable_statement_logging();
|
||||||
|
} else {
|
||||||
|
opt.log_statements(options.sqlx_logging_level);
|
||||||
}
|
}
|
||||||
if options.get_max_connections().is_none() {
|
if options.get_max_connections().is_none() {
|
||||||
options.max_connections(1);
|
options.max_connections(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user