pub struct PgConfig {
pub url: String,
pub host: String,
pub port: u16,
pub database: String,
pub user: String,
pub password: Option<String>,
pub ssl_mode: SslMode,
pub connect_timeout: Duration,
pub statement_timeout: Option<Duration>,
pub application_name: Option<String>,
pub options: Vec<(String, String)>,
}Expand description
PostgreSQL connection configuration.
Fields§
§url: StringDatabase URL.
host: StringHost (extracted from URL or explicit).
port: u16Port (default: 5432).
database: StringDatabase name.
user: StringUsername.
password: Option<String>Password.
ssl_mode: SslModeSSL mode.
With the default tls cargo feature, TLS connections are established
via rustls with certificates verified against the Mozilla root store
(chain + hostname). Without the feature, any TLS-requiring mode fails
at pool build time with a clear error — it is never silently
downgraded to plaintext.
connect_timeout: DurationConnection timeout.
statement_timeout: Option<Duration>Statement timeout.
application_name: Option<String>Application name (shown in pg_stat_activity).
options: Vec<(String, String)>Additional options.
Implementations§
Source§impl PgConfig
impl PgConfig
Sourcepub fn from_url(url: impl Into<String>) -> PgResult<Self>
pub fn from_url(url: impl Into<String>) -> PgResult<Self>
Create a new configuration from a database URL.
Sourcepub fn builder() -> PgConfigBuilder
pub fn builder() -> PgConfigBuilder
Create a builder for configuration.
Sourcepub fn to_pg_config(&self) -> Config
pub fn to_pg_config(&self) -> Config
Convert to tokio-postgres config.
Applies everything tokio_postgres::Config can express without a TLS
connector: host/port/dbname/user/password, application_name,
connect_timeout, the driver’s tokio_postgres::config::SslMode,
plus statement_timeout and any extra options (passed via the
libpq-style options startup parameter as space-separated
-c key=value pairs).
Option pairs whose key is not a valid GUC name, or whose value
contains whitespace / \ / ', are dropped with a warning:
percent-decoded values could otherwise smuggle extra -c
assignments into the space-joined string.
Require/VerifyCa/VerifyFull all map to the driver’s
SslMode::Require; the pool supplies the rustls connector (with
webpki certificate verification) that makes the mode satisfiable.