Skip to main content

Client

Struct Client 

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

Client is a handler type for Driver. it interacts with latter using channel and message for IO operation and de/encoding of postgres protocol in byte format.

Client expose a set of high level API to make the interaction represented in Rust function and types.

§Lifetime

Client and Driver have a dependent lifetime where either side can trigger the other part to shutdown. From Client side it’s in the form of dropping ownership.

§Examples

// connect to a database and spawn driver as async task
let (cli, drv) = Postgres::new(cfg).connect().await?;
let handle = tokio::spawn(drv.into_future());

// drop client after finished usage
drop(cli);

// client would notify driver to shutdown when it's dropped.
// await on the handle would return a Result of the shutdown outcome from driver side.  
let _ = handle.await.unwrap();

Implementations§

Source§

impl Client

Source

pub fn transaction( &mut self, ) -> impl Future<Output = Result<Transaction<'_, Self>, Error>> + Send

start a transaction

Source

pub fn transaction_owned( self, ) -> impl Future<Output = Result<Transaction<'static, Self>, Error>> + Send

owned version of Client::transaction

Source

pub fn copy_in( &mut self, stmt: &Statement, ) -> impl Future<Output = Result<CopyIn<'_, Self>, Error>> + Send

Executes a COPY FROM STDIN statement, returning a sink used to write the copy data.

PostgreSQL does not support parameters in COPY statements, so this method does not take any. The copy must be explicitly completed via CopyIn::finish. If it is not, the copy will be aborted.

Source

pub async fn copy_out(&self, stmt: &Statement) -> Result<CopyOut, Error>

Executes a COPY TO STDOUT statement, returning async stream of the resulting data.

PostgreSQL does not support parameters in COPY statements, so this method does not take any.

Source

pub fn cancel_token(&self) -> Session

Constructs a cancellation token that can later be used to request cancellation of a query running on the connection associated with this client.

Source

pub fn closed(&self) -> bool

a lossy hint of running state of io driver. an io driver shutdown can happen at the same time this api is called.

Source

pub fn typeinfo(&self) -> Option<Statement>

Source

pub fn set_typeinfo(&self, statement: &Statement)

Source

pub fn typeinfo_composite(&self) -> Option<Statement>

Source

pub fn set_typeinfo_composite(&self, statement: &Statement)

Source

pub fn typeinfo_enum(&self) -> Option<Statement>

Source

pub fn set_typeinfo_enum(&self, statement: &Statement)

Source

pub fn type_(&self, oid: Oid) -> Option<Type>

Source

pub fn set_type(&self, oid: Oid, type_: &Type)

Source

pub fn clear_type_cache(&self)

Clears the client’s type information cache.

When user-defined types are used in a query, the client loads their definitions from the database and caches them for the lifetime of the client. If those definitions are changed in the database, this method can be used to flush the local cache and allow the new, updated definitions to be loaded.

Trait Implementations§

Source§

impl ClientBorrow for Client

Source§

impl ClientBorrowMut for Client

Source§

fn borrow_cli_mut(&mut self) -> &mut Client

Source§

impl Copy for Client

Source§

fn send_one_way<F>(&self, func: F) -> Result<(), Error>
where F: FnOnce(&mut BytesMut) -> Result<(), Error>,

Source§

impl Drop for Client

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'c> Execute<&'c Client> for &Path

Available on non-crate feature nightly only.
Source§

type ExecuteOutput = Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'c>>

outcome of execute. used for single time database response: number of rows affected by execution for example.
Source§

type QueryOutput = Pin<Box<dyn Future<Output = Result<GenericRowStream<Vec<Column>, NoTyped>, Error>> + Send + 'c>>

outcome of query. used for repeated database response: database rows for example Read more
Source§

fn execute(self, cli: &'c Client) -> Self::ExecuteOutput

define how a statement is executed with single time response
Source§

fn query(self, cli: &'c Client) -> Self::QueryOutput

define how a statement is queried with repeated response
Source§

impl<'s> Execute<&Client> for &'s Statement

Source§

type ExecuteOutput = ResultFuture<RowAffected>

outcome of execute. used for single time database response: number of rows affected by execution for example.
Source§

type QueryOutput = Ready<Result<GenericRowStream<&'s [Column], Typed>, Error>>

outcome of query. used for repeated database response: database rows for example Read more
Source§

fn execute(self, cli: &Client) -> Self::ExecuteOutput

define how a statement is executed with single time response
Source§

fn query(self, cli: &Client) -> Self::QueryOutput

define how a statement is queried with repeated response
Source§

impl Execute<&Client> for &str

Source§

type ExecuteOutput = ResultFuture<RowAffected>

outcome of execute. used for single time database response: number of rows affected by execution for example.
Source§

type QueryOutput = Ready<Result<GenericRowStream<Vec<Column>, NoTyped>, Error>>

outcome of query. used for repeated database response: database rows for example Read more
Source§

fn execute(self, cli: &Client) -> Self::ExecuteOutput

define how a statement is executed with single time response
Source§

fn query(self, cli: &Client) -> Self::QueryOutput

define how a statement is queried with repeated response
Source§

impl<'c> Execute<&'c Client> for StatementNamed<'_>

Source§

type ExecuteOutput = ResultFuture<IntoGuarded<'c, Pin<Box<dyn Future<Output = Result<Statement, Error>> + Send + 'c>>, Client>>

outcome of execute. used for single time database response: number of rows affected by execution for example.
Source§

type QueryOutput = <StatementNamed<'_> as Execute<&'c Client>>::ExecuteOutput

outcome of query. used for repeated database response: database rows for example Read more
Source§

fn execute(self, cli: &'c Client) -> Self::ExecuteOutput

define how a statement is executed with single time response
Source§

fn query(self, cli: &'c Client) -> Self::QueryOutput

define how a statement is queried with repeated response
Source§

impl<'s, P> Execute<&Client> for StatementPreparedQuery<'s, P>
where P: AsParams,

Source§

type ExecuteOutput = ResultFuture<RowAffected>

outcome of execute. used for single time database response: number of rows affected by execution for example.
Source§

type QueryOutput = Ready<Result<GenericRowStream<&'s [Column], Typed>, Error>>

outcome of query. used for repeated database response: database rows for example Read more
Source§

fn execute(self, cli: &Client) -> Self::ExecuteOutput

define how a statement is executed with single time response
Source§

fn query(self, cli: &Client) -> Self::QueryOutput

define how a statement is queried with repeated response
Source§

impl<'s, P> Execute<&Client> for StatementPreparedQueryOwned<'s, P>
where P: AsParams,

Source§

type ExecuteOutput = ResultFuture<RowAffected>

outcome of execute. used for single time database response: number of rows affected by execution for example.
Source§

type QueryOutput = Ready<Result<GenericRowStream<Arc<[Column]>, Typed>, Error>>

outcome of query. used for repeated database response: database rows for example Read more
Source§

fn execute(self, cli: &Client) -> Self::ExecuteOutput

define how a statement is executed with single time response
Source§

fn query(self, cli: &Client) -> Self::QueryOutput

define how a statement is queried with repeated response
Source§

impl<'c, P> Execute<&'c Client> for StatementQuery<'_, P>
where P: AsParams,

Source§

type ExecuteOutput = ResultFuture<RowAffected>

outcome of execute. used for single time database response: number of rows affected by execution for example.
Source§

type QueryOutput = Ready<Result<RowStreamGuarded<'c, Client>, Error>>

outcome of query. used for repeated database response: database rows for example Read more
Source§

fn execute(self, cli: &Client) -> Self::ExecuteOutput

define how a statement is executed with single time response
Source§

fn query(self, cli: &'c Client) -> Self::QueryOutput

define how a statement is queried with repeated response
Source§

impl<'c, P> Execute<&'c Client> for StatementSingleRTTQuery<'_, P>
where P: AsParams,

Source§

type ExecuteOutput = ResultFuture<RowAffected>

outcome of execute. used for single time database response: number of rows affected by execution for example.
Source§

type QueryOutput = Ready<Result<RowStreamGuarded<'c, Client>, Error>>

outcome of query. used for repeated database response: database rows for example Read more
Source§

fn execute(self, cli: &Client) -> Self::ExecuteOutput

define how a statement is executed with single time response
Source§

fn query(self, cli: &'c Client) -> Self::QueryOutput

define how a statement is queried with repeated response

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