feat: add new error type for nested transaction

This commit is contained in:
Dmitriy Pleshevskiy 2021-10-22 00:56:55 +03:00
parent 877b312b34
commit ff24f783fe
4 changed files with 12 additions and 5 deletions

View file

@ -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)
}
}

View file

@ -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"),

View file

@ -91,7 +91,7 @@ impl<'me> ConnectionClient for Transaction<'me> {
fn start_transaction(&mut self) -> crate::Result<Self::Trx<'_>> {
self.0
.transaction()
.map_err(|_| crate::Error::UpgradeToTransaction)
.map_err(|_| crate::Error::UpgradeToNestedTransaction)
.map(Transaction)
}
}

View file

@ -76,9 +76,9 @@ impl<'me> ConnectionClient for Transaction<'me> {
#[cfg(feature = "nightly")]
fn start_transaction(&mut self) -> crate::Result<Self::Trx<'_>> {
// 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)