pub struct DatabaseConfig {
pub url: String,
pub redacted_url: String,
pub max_connections: u32,
pub min_connections: u32,
pub connect_timeout: Duration,
pub idle_timeout: Duration,
pub max_lifetime: Duration,
pub test_before_acquire: bool,
}Expand description
数据库连接池配置,字段均通过 URI 查询参数解析后填充。
url 含明文密码,因此不派生 Debug:手写实现用 redacted_url 顶替,
避免凭据随 {:?} 进入日志或错误信息。
Fields§
§url: String实际用于建连的 URL(含密码,已去除连接池查询参数)
redacted_url: String密码已替换为 [PASSWORD_MASK] 的 URL,仅用于日志输出
max_connections: u32连接池最大连接数(2–1000)
min_connections: u32连接池最小保活连接数(0–10)
connect_timeout: Duration取得连接的超时时间(含排队等空闲连接与新建连接),映射到 sqlx 的
acquire_timeout。此前解析了却从未应用,实际生效的是 sqlx 默认的 30s。
idle_timeout: Duration连接空闲超时时间,超出后连接将被回收
max_lifetime: Duration连接最大存活时间,超出后强制重建
test_before_acquire: bool取出连接前是否先执行健康检测
Trait Implementations§
Source§impl Clone for DatabaseConfig
impl Clone for DatabaseConfig
Source§impl Debug for DatabaseConfig
impl Debug for DatabaseConfig
Source§impl Default for DatabaseConfig
impl Default for DatabaseConfig
Source§impl Validate for DatabaseConfig
impl Validate for DatabaseConfig
Source§impl<'v_a> ValidateArgs<'v_a> for DatabaseConfig
impl<'v_a> ValidateArgs<'v_a> for DatabaseConfig
Auto Trait Implementations§
impl Freeze for DatabaseConfig
impl RefUnwindSafe for DatabaseConfig
impl Send for DatabaseConfig
impl Sync for DatabaseConfig
impl Unpin for DatabaseConfig
impl UnsafeUnpin for DatabaseConfig
impl UnwindSafe for DatabaseConfig
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
Mutably borrows from an owned value. Read more
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<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> ⓘ
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 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> ⓘ
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