Skip to main content

PgConnectionBuilder

Struct PgConnectionBuilder 

Source
pub struct PgConnectionBuilder { /* private fields */ }
Expand description

Builder for configuring and establishing a PostgreSQL connection.

§Example

use oxisql_postgres::{PgConnectionBuilder, TlsMode};

let conn = PgConnectionBuilder::new()
    .host("localhost")
    .port(5432)
    .dbname("mydb")
    .user("postgres")
    .password("secret")
    .connect()
    .await?;

Implementations§

Source§

impl PgConnectionBuilder

Source

pub fn new() -> Self

Create a new builder with defaults.

Source

pub fn host(self, h: impl Into<String>) -> Self

Set the host.

Source

pub fn port(self, p: u16) -> Self

Set the port.

Source

pub fn dbname(self, db: impl Into<String>) -> Self

Set the database name.

Source

pub fn user(self, u: impl Into<String>) -> Self

Set the username.

Source

pub fn password(self, pw: impl Into<String>) -> Self

Set the password.

Source

pub fn connect_timeout_secs(self, secs: u64) -> Self

Set the connection timeout in seconds.

Source

pub fn tls_mode(self, mode: TlsMode) -> Self

Set the TLS mode.

Source

pub fn tls_skip_verify(self) -> Result<Self, PgError>

Require TLS but skip server certificate verification.

INSECURE — intended for development and testing environments only. Production code should use tls_with_ca_pem or supply a trusted root certificate store via tls_mode with a fully validated TlsMode::Rustls config.

Internally calls TlsMode::skip_verify to build a ClientConfig that accepts all server certificates without validation.

§Errors

Returns PgError::Tls if the rustls ClientConfig cannot be built.

Source

pub fn tls_with_ca_pem(self, ca_pem: Vec<u8>) -> Result<Self, PgError>

Require TLS and verify the server certificate against a custom CA.

ca_pem must be a PEM-encoded certificate authority certificate. Multiple certificates may be concatenated in a single Vec<u8>.

Internally calls TlsMode::with_ca_pem to build a ClientConfig that trusts the supplied CA in addition to the Mozilla WebPKI bundle.

§Errors

Returns PgError::Tls if the PEM cannot be parsed or is empty.

Source

pub async fn connect(self) -> Result<PgConnection, PgError>

Establish the connection.

Trait Implementations§

Source§

impl Default for PgConnectionBuilder

Source§

fn default() -> Self

Returns the “default value” for a 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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more