pub struct Config {
pub host: String,
pub port: u16,
pub user: String,
pub password: String,
pub database: String,
pub ssl: SslMode,
pub statement_timeout_secs: u32,
pub statement_cache_mode: StatementCacheMode,
pub ssl_root_cert: Option<String>,
pub ssl_cert: Option<String>,
pub ssl_key: Option<String>,
}Expand description
Implements Drop to zeroize the password field, minimizing the window where plaintext credentials live in memory.
Fields§
§host: String§port: u16§user: String§password: String§database: String§ssl: SslMode§statement_timeout_secs: u32PG-side statement timeout in seconds. Default: 30. 0 = no timeout.
After connecting, the driver sends SET statement_timeout = '{N}s'.
If a query exceeds this duration, PostgreSQL kills it and returns an error.
statement_cache_mode: StatementCacheModeStatement cache mode. Default: StatementCacheMode::Named.
Set to StatementCacheMode::Disabled for pgbouncer/PgCat transaction
pooling compatibility. When disabled, every query uses the unnamed
prepared statement — no server-side statement caching.
ssl_root_cert: Option<String>Path to PEM file containing CA certificate(s) for server verification. When set, these CAs are used instead of the system defaults.
ssl_cert: Option<String>Path to PEM file containing client certificate for mTLS.
ssl_key: Option<String>Path to PEM file containing client private key for mTLS.
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_url(url: &str) -> Result<Self, DriverError>
pub fn from_url(url: &str) -> Result<Self, DriverError>
Parse a PostgreSQL connection URL.
Format: postgres://user:password@host:port/database?sslmode=prefer
§Examples
use bsql_driver_postgres::Config;
let config = Config::from_url("postgres://alice:secret@db.example.com:5432/myapp").unwrap();
assert_eq!(config.user, "alice");
assert_eq!(config.host, "db.example.com");
assert_eq!(config.port, 5432);
assert_eq!(config.database, "myapp");pgbouncer-compatible connection:
use bsql_driver_postgres::{Config, StatementCacheMode};
let config = Config::from_url(
"postgres://user:pass@pgbouncer:6432/mydb?statement_cache=disabled"
).unwrap();
assert_eq!(config.statement_cache_mode, StatementCacheMode::Disabled);§Unix domain sockets
Use the host query parameter to specify a UDS directory (libpq convention):
postgres://user@localhost/dbname?host=/tmp
postgres:///dbname?host=/var/run/postgresqlWhen host starts with /, the driver connects via Unix domain socket at
{host}/.s.PGSQL.{port} instead of TCP. TLS is skipped for UDS connections.
Sourcepub fn validate(&self) -> Result<(), DriverError>
pub fn validate(&self) -> Result<(), DriverError>
Validate configuration fields before attempting a connection.
Called automatically by from_url(). Call manually if constructing
a Config by hand.
Sourcepub fn host_is_uds(&self) -> bool
pub fn host_is_uds(&self) -> bool
Returns true if the host is a Unix domain socket directory path.
libpq convention: if host starts with /, the connection uses a
Unix domain socket at {host}/.s.PGSQL.{port}.
Sourcepub fn uds_path(&self) -> String
pub fn uds_path(&self) -> String
Returns the Unix domain socket path: {host}/.s.PGSQL.{port}.
Only meaningful when host_is_uds() returns true.