Skip to content

Commit a8ac31a

Browse files
authored
Merge pull request sfackler#724 from vemoo/transaction-client-method
add `client` method to `GenericClient`
2 parents 2ab49f6 + e2d3273 commit a8ac31a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

tokio-postgres/src/generic_client.rs

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ mod private {
1212
/// This trait is "sealed", and cannot be implemented outside of this crate.
1313
#[async_trait]
1414
pub trait GenericClient: private::Sealed {
15+
/// Get a reference to the underlying `Client`
16+
fn client(&self) -> &Client;
17+
1518
/// Like `Client::execute`.
1619
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
1720
where
@@ -74,6 +77,10 @@ impl private::Sealed for Client {}
7477

7578
#[async_trait]
7679
impl GenericClient for Client {
80+
fn client(&self) -> &Client {
81+
self
82+
}
83+
7784
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
7885
where
7986
T: ?Sized + ToStatement + Sync + Send,
@@ -152,6 +159,10 @@ impl private::Sealed for Transaction<'_> {}
152159
#[async_trait]
153160
#[allow(clippy::needless_lifetimes)]
154161
impl GenericClient for Transaction<'_> {
162+
fn client(&self) -> &Client {
163+
self.client()
164+
}
165+
155166
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
156167
where
157168
T: ?Sized + ToStatement + Sync + Send,

tokio-postgres/src/transaction.rs

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ impl<'a> Transaction<'a> {
6464
}
6565
}
6666

67+
/// Get a reference to the underlying `Client`
68+
pub fn client(&self) -> &Client {
69+
&self.client
70+
}
71+
6772
/// Consumes the transaction, committing all changes made within it.
6873
pub async fn commit(mut self) -> Result<(), Error> {
6974
self.done = true;

0 commit comments

Comments
 (0)