#[non_exhaustive]pub struct Config { /* private fields */ }Expand description
Configuration for a PostgreSQL connection.
Use Config::new() to create a default configuration and then set fields
using the builder methods, or parse from a connection string with
Config::from_uri or Config::from_key_value.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new configuration with default values.
Defaults:
- host:
"localhost" - port:
5432 - user:
"postgres" - password:
None - database:
None - ssl_mode:
VerifyFull(if tls feature enabled) /Disable(otherwise) - connect_timeout:
None - target_session_attrs:
Any
Sourcepub fn application_name(self, name: impl Into<String>) -> Self
pub fn application_name(self, name: impl Into<String>) -> Self
Sets the application name.
Sourcepub fn connect_timeout(self, timeout: Duration) -> Self
pub fn connect_timeout(self, timeout: Duration) -> Self
Sets the connection timeout.
Sourcepub fn statement_timeout(self, timeout: Duration) -> Self
pub fn statement_timeout(self, timeout: Duration) -> Self
Sets the statement timeout (sent as a startup parameter).
Sourcepub fn target_session_attrs(self, attrs: TargetSessionAttrs) -> Self
pub fn target_session_attrs(self, attrs: TargetSessionAttrs) -> Self
Sets the target session attributes.
Sourcepub fn option(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn option(self, key: impl Into<String>, value: impl Into<String>) -> Self
Adds an extra startup option.
Sourcepub fn use_tls(self, use_tls: bool) -> Self
pub fn use_tls(self, use_tls: bool) -> Self
Sets whether to use TLS (legacy alias for ssl_mode).
Sourcepub fn accept_invalid_certs(self, accept: bool) -> Self
pub fn accept_invalid_certs(self, accept: bool) -> Self
Accept invalid/self-signed TLS certificates. WARNING: Only for development/testing. Never use in production.
Sourcepub fn allow_insecure_auth(self, allow: bool) -> Self
pub fn allow_insecure_auth(self, allow: bool) -> Self
Allow legacy password authentication over plaintext transports.
This enables cleartext-password and MD5 authentication without TLS. WARNING: Only use this in development or tightly controlled environments.
Sourcepub fn reconnect(self, config: ReconnectConfig) -> Self
pub fn reconnect(self, config: ReconnectConfig) -> Self
Sets the reconnection policy.
Sourcepub fn enable_reconnect(self) -> Self
pub fn enable_reconnect(self) -> Self
Enable automatic reconnection with default settings.
Sourcepub fn max_reconnect_attempts(self, n: u32) -> Self
pub fn max_reconnect_attempts(self, n: u32) -> Self
Set the maximum number of reconnection attempts.
Sourcepub fn stale_threshold(self, threshold: Duration) -> Self
pub fn stale_threshold(self, threshold: Duration) -> Self
Set the stale connection detection threshold.
Sourcepub fn stale(self, config: StaleConfig) -> Self
pub fn stale(self, config: StaleConfig) -> Self
Sets the stale connection detection configuration.
pub fn get_host(&self) -> &str
pub fn get_port(&self) -> u16
pub fn get_user(&self) -> &str
pub fn get_password(&self) -> Option<&str>
pub fn get_database(&self) -> Option<&str>
pub fn get_application_name(&self) -> Option<&str>
pub fn get_ssl_mode(&self) -> SslMode
pub fn get_connect_timeout(&self) -> Option<Duration>
pub fn get_statement_timeout(&self) -> Option<Duration>
pub fn get_target_session_attrs(&self) -> TargetSessionAttrs
pub fn get_use_tls(&self) -> bool
pub fn get_accept_invalid_certs(&self) -> bool
pub fn get_allow_insecure_auth(&self) -> bool
pub fn get_keepalive(&self) -> Option<Duration>
pub fn get_reconnect(&self) -> &ReconnectConfig
pub fn get_stale(&self) -> &StaleConfig
Sourcepub fn startup_params(&self) -> Vec<(String, String)>
pub fn startup_params(&self) -> Vec<(String, String)>
Returns the startup parameters to send in the StartupMessage.
Sourcepub fn from_uri(uri: &str) -> Result<Self, ConfigError>
pub fn from_uri(uri: &str) -> Result<Self, ConfigError>
Parse a PostgreSQL connection URI.
Supported format:
postgresql://[user[:password]@][host][:port][/dbname][?param1=value1&...]Sourcepub fn from_key_value(s: &str) -> Result<Self, ConfigError>
pub fn from_key_value(s: &str) -> Result<Self, ConfigError>
Parse a key-value connection string.
Format:
host=localhost port=5432 dbname=mydb user=myuser password=secret sslmode=requireValues containing spaces may be wrapped in single quotes:
host='my host' user=postgresSourcepub fn from_env() -> Result<Self, ConfigError>
pub fn from_env() -> Result<Self, ConfigError>
Build a configuration from standard PostgreSQL environment variables.
Variables: PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD,
PGSSLMODE, PGCONNECT_TIMEOUT, PGAPPNAME.