From ff24f783fec7a52a99e8158bb72a5ba3e6121378 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 22 Oct 2021 00:56:55 +0300 Subject: [PATCH] feat: add new error type for nested transaction --- src/bb8_postgres.rs | 2 +- src/error.rs | 7 +++++++ src/r2d2_postgres.rs | 2 +- src/r2d2_sqlite.rs | 6 +++--- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/bb8_postgres.rs b/src/bb8_postgres.rs index 81f8d7a..b658276 100644 --- a/src/bb8_postgres.rs +++ b/src/bb8_postgres.rs @@ -97,7 +97,7 @@ impl<'me> ConnectionClient for Transaction<'me> { self.0 .transaction() .await - .map_err(|_| crate::Error::UpgradeToTransaction) + .map_err(|_| crate::Error::UpgradeToNestedTransaction) .map(Transaction) } } diff --git a/src/error.rs b/src/error.rs index 035e053..16dff64 100644 --- a/src/error.rs +++ b/src/error.rs @@ -25,6 +25,9 @@ pub enum Error { /// Returns if we cannot upgrade connection to transaction. #[cfg(feature = "nightly")] UpgradeToTransaction, + /// Returns if we cannot upgrade transaction to a nested one. + #[cfg(feature = "nightly")] + UpgradeToNestedTransaction, /// Returns if we cannot commit transaction. #[cfg(feature = "nightly")] CommitTransaction, @@ -42,6 +45,10 @@ impl fmt::Display for Error { #[cfg(feature = "nightly")] Error::UpgradeToTransaction => f.write_str("Cannot upgrade connection to transaction"), #[cfg(feature = "nightly")] + Error::UpgradeToNestedTransaction => { + f.write_str("Cannot upgrade transaction to a nested one") + } + #[cfg(feature = "nightly")] Error::CommitTransaction => f.write_str("Cannot commit changes of transaction"), #[cfg(feature = "nightly")] Error::RollbackTransaction => f.write_str("Cannot rolls transaction back"), diff --git a/src/r2d2_postgres.rs b/src/r2d2_postgres.rs index 8be97ef..b3a70be 100644 --- a/src/r2d2_postgres.rs +++ b/src/r2d2_postgres.rs @@ -91,7 +91,7 @@ impl<'me> ConnectionClient for Transaction<'me> { fn start_transaction(&mut self) -> crate::Result> { self.0 .transaction() - .map_err(|_| crate::Error::UpgradeToTransaction) + .map_err(|_| crate::Error::UpgradeToNestedTransaction) .map(Transaction) } } diff --git a/src/r2d2_sqlite.rs b/src/r2d2_sqlite.rs index 85dc7e4..32732cf 100644 --- a/src/r2d2_sqlite.rs +++ b/src/r2d2_sqlite.rs @@ -76,9 +76,9 @@ impl<'me> ConnectionClient for Transaction<'me> { #[cfg(feature = "nightly")] fn start_transaction(&mut self) -> crate::Result> { // At the moment we cannot implement nested transaction because - // the transaction in `rusqlite` requires DerefMut, which cannot be - // implemented yet 😣 - unimplemented!() + // the transaction in `rusqlite` 😣 We need to implement + // our box for transaction if we want to use it here. + Err(crate::Error::UpgradeToNestedTransaction) // self.0 // .transaction() // .map_err(|_| error::PersistenceError::UpgradeToTransaction)