Skip to main content

DatabaseConfig

Struct DatabaseConfig 

Source
pub struct DatabaseConfig {
Show 13 fields pub driver: String, pub host: String, pub port: u16, pub user: String, pub password: String, pub database: String, pub application_name: String, pub max_connections: usize, pub connect_timeout: Duration, pub query_timeout: Duration, pub tls_mode: TlsMode, pub tls_root_certificate: Option<String>, pub credentials: Option<Credentials>,
}

Fields§

§driver: String

Which database this points at: postgres, mysql, sqlserver.

§host: String§port: u16§user: String§password: String§database: String§application_name: String§max_connections: usize

Connections kept open by the pool.

§connect_timeout: Duration§query_timeout: Duration

How long a query may run before the driver gives up on it.

§tls_mode: TlsMode

Whether to encrypt the connection, and how much of the certificate to believe. See crate::tls::TlsMode — the default asks for encryption but accepts a server that declines, which guarantees nothing.

§tls_root_certificate: Option<String>

A PEM file of trust anchors, for verify-ca and verify-full against a private CA. None uses the public roots.

§credentials: Option<Credentials>

Credentials that may be replaced while the process runs, for a dynamic account issued by a secret store. None means user and password above are the whole story and never change.

Implementations§

Source§

impl DatabaseConfig

Source

pub fn from_url(url: &str) -> Result<Self>

Parse a database URL.

The scheme chooses the driver: postgres://, mysql:// or sqlserver://. User, password and database are percent-decoded, so a password with an @ or / in it works without escaping anything twice.

Source

pub fn resolved(&self) -> DatabaseConfig

This configuration with the credentials that are current now.

Every driver calls this on the way into a connect rather than reading user and password directly, which is the single point where a rotation takes effect. Without it a rotated credential would sit in the config being ignored.

Source

pub fn generation(&self) -> u64

Which generation of credentials a connection opened now belongs to.

Zero when nothing rotates, so a pool holding static credentials never retires anything.

Source

pub fn dialect(&self) -> Result<Box<dyn Dialect>>

The dialect this configuration implies.

Source

pub fn from_app_config(config: &Config) -> Result<Self>

Read from the application config, falling back to DATABASE_URL.

Source

pub fn redacted_url(&self) -> String

The URL with the password removed, for logs and error messages.

Trait Implementations§

Source§

impl Clone for DatabaseConfig

Source§

fn clone(&self) -> DatabaseConfig

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

impl Default for DatabaseConfig

Source§

fn default() -> Self

Returns the “default value” for a type. 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.