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,
impl<TLS> PGRobustClient<TLS>where
TLS: MakeTlsConnect<Socket> + Clone,
<TLS as MakeTlsConnect<Socket>>::Stream: Send + Sync + 'static,
Sourcepub async fn spawn(
config: PGRobustClientConfig<TLS>,
) -> PGResult<PGRobustClient<TLS>>
pub async fn spawn( config: PGRobustClientConfig<TLS>, ) -> PGResult<PGRobustClient<TLS>>
Connects to the database and returns a new client.
Sourcepub fn config(&self) -> &PGRobustClientConfig<TLS>
pub fn config(&self) -> &PGRobustClientConfig<TLS>
Returns a reference to the config object used to create this client.
Sourcepub fn config_mut(&mut self) -> &mut PGRobustClientConfig<TLS>
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.
Sourcepub async fn cancel_query(&mut self) -> PGResult<()>
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.
Sourcepub fn capture_and_clear_log(&mut self) -> Vec<PGMessage>
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.
Sourcepub async fn with_captured_log<F, T>(
&mut self,
f: F,
) -> PGResult<(T, Vec<PGMessage>)>
pub async fn with_captured_log<F, T>( &mut self, f: F, ) -> PGResult<(T, Vec<PGMessage>)>
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.
Sourcepub async fn wrap_reconnect<T>(
&mut self,
max_dur: Option<Duration>,
factory: impl AsyncFn(&mut PGClient) -> Result<T, Error>,
) -> PGResult<T>
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 lose the connection during a query, the client will automatically reconnect and retry the query.
Note: This method clears the message log at the start of each call.
Messages from previous operations are discarded. Use with_captured_log
if you need to preserve and retrieve messages from a specific operation.
pub async fn subscribe_notify( &mut self, channels: &[impl AsRef<str> + Send + Sync + 'static], timeout: Option<Duration>, ) -> PGResult<()>
pub async fn unsubscribe_notify( &mut self, channels: &[impl AsRef<str> + Send + Sync + 'static], timeout: Option<Duration>, ) -> PGResult<()>
Sourcepub async fn unsubscribe_notify_all(
&mut self,
timeout: Option<Duration>,
) -> PGResult<()>
pub async fn unsubscribe_notify_all( &mut self, timeout: Option<Duration>, ) -> PGResult<()>
Unsubscribes from all channels.
Sourcepub 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,
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].
Sourcepub async fn query<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
timeout: Option<Duration>,
) -> PGResult<Vec<Row>>
pub async fn query<T>( &mut self, query: &T, params: &[&(dyn ToSql + Sync)], timeout: Option<Duration>, ) -> PGResult<Vec<Row>>
Like [Client::query].
Note: Parameters are cloned into a Vec before the async operation
to satisfy lifetime requirements. For bulk operations with many large
parameters, consider using query_raw or execute_raw
which may be more efficient depending on your use case.
Sourcepub async fn query_one<T>(
&mut self,
statement: &T,
params: &[&(dyn ToSql + Sync)],
timeout: Option<Duration>,
) -> PGResult<Row>
pub async fn query_one<T>( &mut self, statement: &T, params: &[&(dyn ToSql + Sync)], timeout: Option<Duration>, ) -> PGResult<Row>
Like [Client::query_one].
Sourcepub async fn query_opt<T>(
&mut self,
statement: &T,
params: &[&(dyn ToSql + Sync)],
timeout: Option<Duration>,
) -> PGResult<Option<Row>>
pub async fn query_opt<T>( &mut self, statement: &T, params: &[&(dyn ToSql + Sync)], timeout: Option<Duration>, ) -> PGResult<Option<Row>>
Like [Client::query_opt].
Sourcepub 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,
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].
Sourcepub async fn query_typed(
&mut self,
statement: &str,
params: &[(&(dyn ToSql + Sync), Type)],
timeout: Option<Duration>,
) -> PGResult<Vec<Row>>
pub async fn query_typed( &mut self, statement: &str, params: &[(&(dyn ToSql + Sync), Type)], timeout: Option<Duration>, ) -> PGResult<Vec<Row>>
Like [Client::query_typed]
Sourcepub async fn query_typed_raw<P, I>(
&mut self,
statement: &str,
params: I,
timeout: Option<Duration>,
) -> PGResult<RowStream>
pub async fn query_typed_raw<P, I>( &mut self, statement: &str, params: I, timeout: Option<Duration>, ) -> PGResult<RowStream>
Like [Client::query_typed_raw]
Sourcepub async fn prepare(
&mut self,
query: &str,
timeout: Option<Duration>,
) -> PGResult<Statement>
pub async fn prepare( &mut self, query: &str, timeout: Option<Duration>, ) -> PGResult<Statement>
Like [Client::prepare].
Sourcepub async fn prepare_typed(
&mut self,
query: &str,
parameter_types: &[Type],
timeout: Option<Duration>,
) -> PGResult<Statement>
pub async fn prepare_typed( &mut self, query: &str, parameter_types: &[Type], timeout: Option<Duration>, ) -> PGResult<Statement>
Like [Client::prepare_typed].
Sourcepub async fn transaction<F>(
&mut self,
timeout: Option<Duration>,
f: F,
) -> PGResult<()>
pub async fn transaction<F>( &mut self, timeout: Option<Duration>, f: F, ) -> PGResult<()>
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.
Sourcepub async fn batch_execute(
&mut self,
query: &str,
timeout: Option<Duration>,
) -> PGResult<()>
pub async fn batch_execute( &mut self, query: &str, timeout: Option<Duration>, ) -> PGResult<()>
Like [Client::batch_execute].
Sourcepub async fn simple_query(
&mut self,
query: &str,
timeout: Option<Duration>,
) -> PGResult<Vec<SimpleQueryMessage>>
pub async fn simple_query( &mut self, query: &str, timeout: Option<Duration>, ) -> PGResult<Vec<SimpleQueryMessage>>
Like [Client::simple_query].
Sourcepub fn client(&self) -> &Client
pub fn client(&self) -> &Client
Returns a reference to the underlying tokio_postgres::Client.