From e2d327399b6ff423a1921fdb4f41b4a584386bac Mon Sep 17 00:00:00 2001 From: Bernardo Uriarte Blanco Date: Sat, 26 Dec 2020 23:17:04 +0100 Subject: [PATCH] add `client` method to `GenericClient` --- tokio-postgres/src/generic_client.rs | 11 +++++++++++ tokio-postgres/src/transaction.rs | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/tokio-postgres/src/generic_client.rs b/tokio-postgres/src/generic_client.rs index df2c6b842..911a587b6 100644 --- a/tokio-postgres/src/generic_client.rs +++ b/tokio-postgres/src/generic_client.rs @@ -12,6 +12,9 @@ mod private { /// This trait is "sealed", and cannot be implemented outside of this crate. #[async_trait] pub trait GenericClient: private::Sealed { + /// Get a reference to the underlying `Client` + fn client(&self) -> &Client; + /// Like `Client::execute`. async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result where @@ -74,6 +77,10 @@ impl private::Sealed for Client {} #[async_trait] impl GenericClient for Client { + fn client(&self) -> &Client { + self + } + async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result where T: ?Sized + ToStatement + Sync + Send, @@ -152,6 +159,10 @@ impl private::Sealed for Transaction<'_> {} #[async_trait] #[allow(clippy::needless_lifetimes)] impl GenericClient for Transaction<'_> { + fn client(&self) -> &Client { + self.client() + } + async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result where T: ?Sized + ToStatement + Sync + Send, diff --git a/tokio-postgres/src/transaction.rs b/tokio-postgres/src/transaction.rs index 45e9cc3aa..cf39d9186 100644 --- a/tokio-postgres/src/transaction.rs +++ b/tokio-postgres/src/transaction.rs @@ -64,6 +64,11 @@ impl<'a> Transaction<'a> { } } + /// Get a reference to the underlying `Client` + pub fn client(&self) -> &Client { + &self.client + } + /// Consumes the transaction, committing all changes made within it. pub async fn commit(mut self) -> Result<(), Error> { self.done = true;