Skip to main content

SqlxConfig

Struct SqlxConfig 

Source
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

Source

pub fn pool(&self) -> PoolParams

未配置的字段一律取 PoolParams::default —— 默认值只此一处定义, 避免与 PoolParams::for_url 静默分叉。

Source

pub fn query_timeout(&self) -> Option<Duration>

0 表示显式禁用超时;未配置时为 30 秒。

Source

pub fn slow_query(&self) -> Option<Duration>

0 表示显式关闭慢查询告警;未配置时为 1 秒(与 Self::query_timeout 同族语义:0 是「关」而不是「立刻全算慢」)。

Source

pub fn effective_session_init(&self) -> Vec<String>

会话初始化语句:显式配置优先,未配置时按方言取默认 (见 dialect_session_init)。

显式空数组会覆盖方言默认,即主动关闭会话初始化 (与 query_timeout_secs: 0 表示禁用同族)。

Trait Implementations§

Source§

impl Clone for SqlxConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SqlxConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SqlxConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more