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 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 ClientBorrowMut for Client

Source§

fn _borrow_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 Prepare for Client

Source§

fn _get_type( &self, oid: Oid, ) -> Pin<Box<dyn Future<Output = Result<Type, Error>> + Send + '_>>

Source§

fn _get_type_blocking(&self, oid: Oid) -> Result<Type, Error>

Source§

impl Query for Client

Source§

fn _send_encode_query<S>(&self, stmt: S) -> Result<(S::Output, Response), Error>
where S: Encode,

encode statement and params and send it to client driver
Source§

fn _query<S>( &self, stmt: S, ) -> Result<<S::Output as IntoResponse>::Response, Error>
where S: Encode,

query with statement and dynamic typed params. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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