pub struct DatabaseConfig {
pub url: String,
pub max_connections: u32,
pub min_connections: u32,
pub connect_timeout: u64,
pub idle_timeout: u64,
pub max_lifetime: u64,
pub test_before_acquire: bool,
pub statement_timeout_ms: Option<u64>,
pub lock_timeout_ms: Option<u64>,
pub slow_query_threshold_ms: u64,
pub after_connect: Vec<String>,
}Expand description
Database connection configuration. Backend-agnostic — works for PostgreSQL, MySQL, MariaDB, SQLite.
Fields§
§url: String§max_connections: u32§min_connections: u32§connect_timeout: u64§idle_timeout: u64§max_lifetime: u64Close connections older than this many seconds (lets the DB rebalance, frees server memory).
test_before_acquire: boolPing each connection before handing it out. Off by default: saves one round-trip per acquire; enable behind proxies or failover setups that kill idle connections silently.
statement_timeout_ms: Option<u64>Postgres statement_timeout in milliseconds, set at connection startup. None = server default.
lock_timeout_ms: Option<u64>Postgres lock_timeout in milliseconds, set at connection startup. None = server default.
slow_query_threshold_ms: u64Queries slower than this (milliseconds) are logged at WARN (SQL text only, never bound values).
after_connect: Vec<String>SQL statements executed on every new connection. Useful for strict mode, timezone, charset, search_path, etc.
Implementations§
Source§impl DatabaseConfig
impl DatabaseConfig
pub fn redact_url(url: &str) -> String
Sourcepub fn from_url(url: impl Into<String>) -> Self
pub fn from_url(url: impl Into<String>) -> Self
Build from a full connection URL. Examples: postgres://user:pass@localhost:5432/mydb mysql://user:pass@localhost:3306/mydb sqlite:///path/to/db.sqlite3
Sourcepub fn from_env() -> Result<Self, VarError>
pub fn from_env() -> Result<Self, VarError>
Build from environment variable (defaults to DATABASE_URL).
pub fn from_env_var(var: &str) -> Result<Self, VarError>
Sourcepub fn backend(&self) -> BackendKind
pub fn backend(&self) -> BackendKind
Detect the backend kind from the URL scheme.