PGRobustClient

Struct PGRobustClient 

Source
pub struct PGRobustClient<TLS> { /* private fields */ }

Implementations§

Source§

impl<TLS> PGRobustClient<TLS>
where TLS: MakeTlsConnect<Socket> + Clone, <TLS as MakeTlsConnect<Socket>>::Stream: Send + Sync + 'static,

Source

pub async fn spawn( config: PGRobustClientConfig<TLS>, ) -> PGResult<PGRobustClient<TLS>>

Connects to the database and returns a new client.

Source

pub fn config(&self) -> &PGRobustClientConfig<TLS>

Returns a reference to the config object used to create this client.

Source

pub fn config_mut(&mut self) -> &mut PGRobustClientConfig<TLS>

Returns a mutable reference to the config object used to create this client. Some changes only take effect on the next connection. Others are immediate.

Source

pub async fn cancel_query(&mut self) -> PGResult<()>

Cancels any query in-progress.

This is the only function that does not take a timeout nor does it attempt to reconnect if the connection is lost. It will simply return the original error.

Source

pub fn capture_and_clear_log(&mut self) -> Vec<PGMessage>

Returns the log messages captured since the last call to this function. It also clears the log.

Source

pub async fn with_captured_log<F, T>( &mut self, f: F, ) -> PGResult<(T, Vec<PGMessage>)>
where F: AsyncFn(&mut Self) -> PGResult<T>,

Given an async closure taking the postgres client, returns the result of said closure along with the accumulated log since the beginning of the closure.

If you use query pipelining then collect the logs for all queries in the pipeline. Otherwise, the logs might not be what you expect.

Source

pub async fn wrap_reconnect<T>( &mut self, max_dur: Option<Duration>, factory: impl AsyncFn(&mut PGClient) -> Result<T, Error>, ) -> PGResult<T>

Wraps most calls that use the client with a timeout and reconnect loop.

If you loose the connection during a query, the client will automatically reconnect and retry the query.

Source

pub async fn subscribe_notify( &mut self, channels: &[impl AsRef<str> + Send + Sync + 'static], timeout: Option<Duration>, ) -> PGResult<()>

Source

pub async fn unsubscribe_notify( &mut self, channels: &[impl AsRef<str> + Send + Sync + 'static], timeout: Option<Duration>, ) -> PGResult<()>

Source

pub async fn unsubscribe_notify_all( &mut self, timeout: Option<Duration>, ) -> PGResult<()>

Unsubscribes from all channels.

Source

pub async fn execute_raw<P, I, T>( &mut self, statement: &T, params: I, timeout: Option<Duration>, ) -> PGResult<u64>
where T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql + Clone + Send + Sync, I: IntoIterator<Item = P> + Sync + Send, I::IntoIter: ExactSizeIterator,

Like [Client::execute_raw].

Source

pub async fn query<T>( &mut self, query: &T, params: &[&(dyn ToSql + Sync)], timeout: Option<Duration>, ) -> PGResult<Vec<Row>>
where T: ?Sized + ToStatement + Sync + Send,

Like [Client::query].

Source

pub async fn query_one<T>( &mut self, statement: &T, params: &[&(dyn ToSql + Sync)], timeout: Option<Duration>, ) -> PGResult<Row>
where T: ?Sized + ToStatement + Sync + Send,

Like [Client::query_one].

Source

pub async fn query_opt<T>( &mut self, statement: &T, params: &[&(dyn ToSql + Sync)], timeout: Option<Duration>, ) -> PGResult<Option<Row>>
where T: ?Sized + ToStatement + Sync + Send,

Like [Client::query_opt].

Source

pub async fn query_raw<T, P, I>( &mut self, statement: &T, params: I, timeout: Option<Duration>, ) -> PGResult<RowStream>
where T: ?Sized + ToStatement + Sync + Send, P: BorrowToSql + Clone + Send + Sync, I: IntoIterator<Item = P> + Sync + Send, I::IntoIter: ExactSizeIterator,

Like [Client::query_raw].

Source

pub async fn query_typed( &mut self, statement: &str, params: &[(&(dyn ToSql + Sync), Type)], timeout: Option<Duration>, ) -> PGResult<Vec<Row>>

Like [Client::query_typed]

Source

pub async fn query_typed_raw<P, I>( &mut self, statement: &str, params: I, timeout: Option<Duration>, ) -> PGResult<RowStream>
where P: BorrowToSql + Clone + Send + Sync, I: IntoIterator<Item = (P, Type)> + Sync + Send,

Like [Client::query_typed_raw]

Source

pub async fn prepare( &mut self, query: &str, timeout: Option<Duration>, ) -> PGResult<Statement>

Like [Client::prepare].

Source

pub async fn prepare_typed( &mut self, query: &str, parameter_types: &[Type], timeout: Option<Duration>, ) -> PGResult<Statement>

Like [Client::prepare_typed].

Source

pub async fn transaction<F>( &mut self, timeout: Option<Duration>, f: F, ) -> PGResult<()>
where for<'a> F: AsyncFn(&'a mut Transaction<'_>) -> Result<(), Error>,

Similar but not quite the same as [Client::transaction].

Executes the closure as a single transaction. Commit is automatically called after the closure. If any connection issues occur during the transaction then the transaction is rolled back (on drop) and retried a new with the new connection subject to the maximum number of reconnect attempts.

Source

pub async fn batch_execute( &mut self, query: &str, timeout: Option<Duration>, ) -> PGResult<()>

Like [Client::batch_execute].

Source

pub async fn simple_query( &mut self, query: &str, timeout: Option<Duration>, ) -> PGResult<Vec<SimpleQueryMessage>>

Like [Client::simple_query].

Source

pub fn client(&self) -> &Client

Returns a reference to the underlying tokio_postgres::Client.

Auto Trait Implementations§

§

impl<TLS> Freeze for PGRobustClient<TLS>
where TLS: Freeze,

§

impl<TLS> !RefUnwindSafe for PGRobustClient<TLS>

§

impl<TLS> Send for PGRobustClient<TLS>
where TLS: Send,

§

impl<TLS> Sync for PGRobustClient<TLS>
where TLS: Sync,

§

impl<TLS> Unpin for PGRobustClient<TLS>
where TLS: Unpin,

§

impl<TLS> !UnwindSafe for PGRobustClient<TLS>

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

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