pub struct SqlxConfig {Show 14 fields
pub url: String,
pub username: Option<String>,
pub password: Option<String>,
pub tls: Option<TlsClientConfig>,
pub session_init: Option<Vec<String>>,
pub mysql_compat: Option<MysqlCompat>,
pub max_connections: Option<u32>,
pub min_connections: Option<u32>,
pub acquire_timeout_secs: Option<u64>,
pub idle_timeout_secs: Option<u64>,
pub max_lifetime_secs: Option<u64>,
pub query_timeout_secs: Option<u64>,
pub slow_query_ms: Option<u64>,
pub test_before_acquire: Option<bool>,
}Fields§
§url: String§username: Option<String>§password: Option<String>§tls: Option<TlsClientConfig>当前不支持。SQLx 的 TLS 走 URL 参数(如 ?sslmode=require);
设了本字段会在 crate::SqlxClient::from_config 处报错,
而不是静默忽略。
session_init: Option<Vec<String>>会话初始化语句;未配置时按方言给默认值,见
SqlxConfig::effective_session_init。
mysql_compat: Option<MysqlCompat>MySQL 协议兼容模式。仅对 mysql:// URL 生效;未配置 = MysqlCompat::Mysql。
Doris / StarRocks 请显式设为 "doris" / "starrocks",否则 sqlx 的默认
建连 SET sql_mode=(SELECT ...) 可能在 StarRocks 上直接失败。
max_connections: Option<u32>§min_connections: Option<u32>§acquire_timeout_secs: Option<u64>取连接的最长等待。注意 0 不是「禁用」 —— sqlx 对
acquire_timeout(Duration::ZERO) 的处理是立即超时(拿不到连接就失败),
与 SqlxConfig::query_timeout_secs 的 0(禁用)语义不同。
idle_timeout_secs: Option<u64>§max_lifetime_secs: Option<u64>§query_timeout_secs: Option<u64>0 = 禁用查询超时。
slow_query_ms: Option<u64>慢查询告警阈值(毫秒)。未配置 = 1000;0 = 不打告警。
只有 tracing feature 会读它 —— feature 关闭时本字段被解析但不生效。
test_before_acquire: Option<bool>每次从池取连接是否先 ping。默认 false:sqlx 默认在每次 acquire
都 ping(不论上次 ping 多近,见 sqlx issue #1743),在高频路径上是
一笔无谓往返。关掉后由 max_lifetime + 查询超时 + 首次使用报错兜底。
Implementations§
Source§impl SqlxConfig
impl SqlxConfig
Sourcepub fn pool(&self) -> PoolParams
pub fn pool(&self) -> PoolParams
未配置的字段一律取 PoolParams::default —— 默认值只此一处定义,
避免与 PoolParams::for_url 静默分叉。
Sourcepub fn query_timeout(&self) -> Option<Duration>
pub fn query_timeout(&self) -> Option<Duration>
0 表示显式禁用超时;未配置时为 30 秒。
Sourcepub fn slow_query(&self) -> Option<Duration>
pub fn slow_query(&self) -> Option<Duration>
0 表示显式关闭慢查询告警;未配置时为 1 秒(与 Self::query_timeout
同族语义:0 是「关」而不是「立刻全算慢」)。
Sourcepub fn effective_session_init(&self) -> Vec<String>
pub fn effective_session_init(&self) -> Vec<String>
会话初始化语句:显式配置优先,未配置时按方言取默认
(见 dialect_session_init)。
显式空数组会覆盖方言默认,即主动关闭会话初始化
(与 query_timeout_secs: 0 表示禁用同族)。
Trait Implementations§
Source§impl Clone for SqlxConfig
impl Clone for SqlxConfig
Source§impl Debug for SqlxConfig
impl Debug for SqlxConfig
Source§impl<'de> Deserialize<'de> for SqlxConfig
impl<'de> Deserialize<'de> for SqlxConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for SqlxConfig
impl RefUnwindSafe for SqlxConfig
impl Send for SqlxConfig
impl Sync for SqlxConfig
impl Unpin for SqlxConfig
impl UnsafeUnpin for SqlxConfig
impl UnwindSafe for SqlxConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request