PgConnection

Struct PgConnection 

Source
pub struct PgConnection<State> { /* private fields */ }
Expand description

Typestate wrapper around a pooled Postgres client.

Implementations§

Source§

impl PgConnection<Idle>

Source

pub async fn from_pool( pool: &Pool<PgManager>, ) -> Result<Self, SqlMiddlewareDbError>

Checkout a connection from the pool.

§Errors

Returns SqlMiddlewareDbError if acquiring the connection fails.

Source§

impl PgConnection<Idle>

Source

pub async fn execute_batch( &mut self, sql: &str, ) -> Result<(), SqlMiddlewareDbError>

Auto-commit batch (BEGIN/COMMIT around it).

§Errors

Returns SqlMiddlewareDbError if the batch execution fails.

Source

pub async fn dml( &mut self, query: &str, params: &[RowValues], ) -> Result<usize, SqlMiddlewareDbError>

Auto-commit DML.

§Errors

Returns SqlMiddlewareDbError if executing the DML fails.

Source§

impl PgConnection<InTx>

Source

pub async fn execute_batch( &mut self, sql: &str, ) -> Result<(), SqlMiddlewareDbError>

Execute batch inside the open transaction.

§Errors

Returns SqlMiddlewareDbError if executing the batch fails.

Source

pub async fn dml( &mut self, query: &str, params: &[RowValues], ) -> Result<usize, SqlMiddlewareDbError>

Execute DML inside the open transaction.

§Errors

Returns SqlMiddlewareDbError if executing the DML fails.

Source§

impl PgConnection<Idle>

Source

pub async fn select( &mut self, query: &str, params: &[RowValues], ) -> Result<ResultSet, SqlMiddlewareDbError>

Auto-commit SELECT.

§Errors

Returns SqlMiddlewareDbError if executing the select fails.

Source

pub fn query<'a>(&'a mut self, sql: &'a str) -> QueryBuilder<'a, 'a>

Start a query builder (auto-commit per operation).

Source§

impl PgConnection<InTx>

Source

pub async fn select( &mut self, query: &str, params: &[RowValues], ) -> Result<ResultSet, SqlMiddlewareDbError>

Execute SELECT inside the open transaction.

§Errors

Returns SqlMiddlewareDbError if executing the select fails.

Source

pub fn query<'a>(&'a mut self, sql: &'a str) -> QueryBuilder<'a, 'a>

Start a query builder within the open transaction.

Source§

impl PgConnection<Idle>

Source

pub async fn begin(self) -> Result<PgConnection<InTx>, SqlMiddlewareDbError>

Begin an explicit transaction.

§Errors

Returns SqlMiddlewareDbError if starting the transaction fails.

Source§

impl PgConnection<InTx>

Source

pub async fn commit(self) -> Result<PgConnection<Idle>, SqlMiddlewareDbError>

Commit and return to idle.

§Errors

Returns SqlMiddlewareDbError if the commit fails.

Source

pub async fn rollback(self) -> Result<PgConnection<Idle>, SqlMiddlewareDbError>

Rollback and return to idle.

§Errors

Returns SqlMiddlewareDbError if the rollback fails.

Trait Implementations§

Source§

impl BeginTx for PgConnection<Idle>

Source§

type Tx = PgConnection<InTx>

Source§

fn begin(self) -> impl Future<Output = Result<Self::Tx, SqlMiddlewareDbError>>

Source§

impl<State> Drop for PgConnection<State>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Queryable for PgConnection<Idle>

Source§

fn query<'a>(&'a mut self, sql: &'a str) -> QueryBuilder<'a, 'a>

Source§

impl Queryable for PgConnection<InTx>

Source§

fn query<'a>(&'a mut self, sql: &'a str) -> QueryBuilder<'a, 'a>

Source§

impl TxConn for PgConnection<InTx>

Source§

type Idle = PgConnection<Idle>

Source§

fn commit( self, ) -> impl Future<Output = Result<Self::Idle, SqlMiddlewareDbError>>

Source§

fn rollback( self, ) -> impl Future<Output = Result<Self::Idle, SqlMiddlewareDbError>>

Source§

impl TypedConnOps for PgConnection<Idle>

Source§

fn execute_batch( &mut self, sql: &str, ) -> impl Future<Output = Result<(), SqlMiddlewareDbError>>

Source§

fn dml( &mut self, query: &str, params: &[RowValues], ) -> impl Future<Output = Result<usize, SqlMiddlewareDbError>>

Source§

fn select( &mut self, query: &str, params: &[RowValues], ) -> impl Future<Output = Result<ResultSet, SqlMiddlewareDbError>>

Source§

impl TypedConnOps for PgConnection<InTx>

Source§

fn execute_batch( &mut self, sql: &str, ) -> impl Future<Output = Result<(), SqlMiddlewareDbError>>

Source§

fn dml( &mut self, query: &str, params: &[RowValues], ) -> impl Future<Output = Result<usize, SqlMiddlewareDbError>>

Source§

fn select( &mut self, query: &str, params: &[RowValues], ) -> impl Future<Output = Result<ResultSet, SqlMiddlewareDbError>>

Auto Trait Implementations§

§

impl<State> Freeze for PgConnection<State>

§

impl<State> !RefUnwindSafe for PgConnection<State>

§

impl<State> Send for PgConnection<State>
where State: Send,

§

impl<State> Sync for PgConnection<State>
where State: Sync,

§

impl<State> Unpin for PgConnection<State>
where State: Unpin,

§

impl<State> !UnwindSafe for PgConnection<State>

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

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

Source§

fn vzip(self) -> V