Skip to main content

DatabaseConfig

Struct DatabaseConfig 

Source
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: u64

Close connections older than this many seconds (lets the DB rebalance, frees server memory).

§test_before_acquire: bool

Ping 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: u64

Queries 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

Source

pub fn redact_url(url: &str) -> String

Source

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

Source

pub fn from_env() -> Result<Self, VarError>

Build from environment variable (defaults to DATABASE_URL).

Source

pub fn from_env_var(var: &str) -> Result<Self, VarError>

Source

pub fn backend(&self) -> BackendKind

Detect the backend kind from the URL scheme.

Trait Implementations§

Source§

impl Clone for DatabaseConfig

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 DatabaseConfig

Source§

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

Formats the value using the given formatter. 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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.