Skip to main content

Config

Struct Config 

Source
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: u32

PG-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: StatementCacheMode

Statement 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

Source

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/postgresql

When host starts with /, the driver connects via Unix domain socket at {host}/.s.PGSQL.{port} instead of TCP. TLS is skipped for UDS connections.

Source

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.

Source

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}.

Source

pub fn uds_path(&self) -> String

Returns the Unix domain socket path: {host}/.s.PGSQL.{port}.

Only meaningful when host_is_uds() returns true.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Redact the password field in Debug output to prevent credential leaks in logs, error messages, and {:?} formatting.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Config

Zeroize password on drop to minimize credential lifetime in memory.

Source§

fn drop(&mut self)

Executes the destructor for this 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.