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: StringWhich database this points at: postgres, mysql, sqlserver.
host: String§port: u16§user: String§password: String§database: String§application_name: String§max_connections: usizeConnections kept open by the pool.
connect_timeout: Duration§query_timeout: DurationHow long a query may run before the driver gives up on it.
tls_mode: TlsModeWhether 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
impl DatabaseConfig
Sourcepub fn sqlite(path: &str) -> DatabaseConfig
pub fn sqlite(path: &str) -> DatabaseConfig
A SQLite database at a path.
Everything a server needs — host, port, user, password, TLS — is
meaningless for a file, so none of it is filled in. What a file does
have is a busy timeout, which reuses connect_timeout: both answer
“how long to wait to be let in”.
Three forms, and the difference between the last two is one slash:
| URL | Means |
|---|---|
sqlite://:memory: | a private database in memory, gone at exit |
sqlite://data/app.db | data/app.db, relative to the process |
sqlite:///var/lib/app.db | the absolute path /var/lib/app.db |
Sourcepub fn from_url(url: &str) -> Result<Self>
pub fn from_url(url: &str) -> Result<Self>
Parse a database URL.
The scheme chooses the driver: postgres://, mysql://,
sqlserver:// or sqlite://. User, password and database are percent-decoded, so a
password with an @ or / in it works without escaping anything twice.
Sourcepub fn resolved(&self) -> DatabaseConfig
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.
Sourcepub fn generation(&self) -> u64
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.
Sourcepub fn from_app_config(config: &Config) -> Result<Self>
pub fn from_app_config(config: &Config) -> Result<Self>
Read from the application config, falling back to DATABASE_URL.
Sourcepub fn redacted_url(&self) -> String
pub fn redacted_url(&self) -> String
The URL with the password removed, for logs and error messages.
Trait Implementations§
Source§impl Clone for DatabaseConfig
impl Clone for DatabaseConfig
Source§fn clone(&self) -> DatabaseConfig
fn clone(&self) -> DatabaseConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more