Merge pull request #724 from vemoo/transaction-client-method
add `client` method to `GenericClient`
This commit is contained in:
commit
a8ac31aa0f
@ -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<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
where
|
||||
@ -74,6 +77,10 @@ impl private::Sealed for Client {}
|
||||
|
||||
#[async_trait]
|
||||
impl GenericClient for Client {
|
||||
fn client(&self) -> &Client {
|
||||
self
|
||||
}
|
||||
|
||||
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
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<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user