Struct af_postgres::Client[][src]

pub struct Client { /* fields omitted */ }

A client for executing stataments on a Postgres connection.

The client can be cloned and shared across tasks or threads. All clones share the same connection which executes statements in the order they are received. Statements are sent to Postgres with automatic pipelining to maximize throughput when using multiple clients simultaneously.

Implementations

impl Client[src]

pub async fn execute(
    &self,
    statement: &impl ToStatement + ?Sized,
    params: &[&(dyn ToSql + Sync)]
) -> Result<u64>
[src]

Executes a statement and returns the number of rows affected.

pub fn is_closed(&self) -> bool[src]

Returns true if the client is disconnected.

pub async fn batch_execute(&self, statements: impl AsRef<str>) -> Result[src]

Executes a batch of statements separated by semicolons.

If a statement fails, this function will return the error and stop executing the batch. When executing a batch of statements including transactions, it is the user's responsibility to roll back any running transactions if this function fails.

This function is intended to execute, for example, a SQL file to create the initial schema of a database. When executing individual statements, other functions should be preferred.

pub async fn begin(&self) -> Result[src]

Begins a transaction on the associated connection.

All clones of this client share the same transaction. They will execute statements within the transaction until this client or a clone of it commits or rolls back the transaction. It is the user's responsibilty to ensure consistency when creating a transaction using multiple clones concurrently.

pub async fn commit(&self) -> Result[src]

Commits the running transaction.

pub async fn prepare(&self, query: impl AsRef<str>) -> Result<Statement>[src]

Prepares a statement.

Prepared statements can be used repeatedly, but only by the same Client that created them.

pub async fn query(
    &self,
    query: &impl ToStatement + ?Sized,
    params: &[&(dyn ToSql + Sync)]
) -> Result<RowStream>
[src]

Executes a statement and returns its results as a stream of rows.

pub async fn query_opt(
    &self,
    query: &impl ToStatement + ?Sized,
    params: &[&(dyn ToSql + Sync)]
) -> Result<Option<Row>>
[src]

Executes a statement and optionally returns the first row of the results.

If no rows are returned, this function returns None.

pub async fn query_one(
    &self,
    query: &impl ToStatement + ?Sized,
    params: &[&(dyn ToSql + Sync)]
) -> Result<Row, QueryOneError>
[src]

Executes a statement and returns the first row of the results.

If no rows are returned, this function returns a [NoRowsReturned] error.

pub async fn rollback(&self) -> Result[src]

Rolls back the running transaction.

Trait Implementations

impl Clone for Client[src]

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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