feat: add new error type for nested transaction
This commit is contained in:
parent
877b312b34
commit
ff24f783fe
4 changed files with 12 additions and 5 deletions
|
@ -97,7 +97,7 @@ impl<'me> ConnectionClient for Transaction<'me> {
|
||||||
self.0
|
self.0
|
||||||
.transaction()
|
.transaction()
|
||||||
.await
|
.await
|
||||||
.map_err(|_| crate::Error::UpgradeToTransaction)
|
.map_err(|_| crate::Error::UpgradeToNestedTransaction)
|
||||||
.map(Transaction)
|
.map(Transaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@ pub enum Error {
|
||||||
/// Returns if we cannot upgrade connection to transaction.
|
/// Returns if we cannot upgrade connection to transaction.
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
UpgradeToTransaction,
|
UpgradeToTransaction,
|
||||||
|
/// Returns if we cannot upgrade transaction to a nested one.
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
|
UpgradeToNestedTransaction,
|
||||||
/// Returns if we cannot commit transaction.
|
/// Returns if we cannot commit transaction.
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
CommitTransaction,
|
CommitTransaction,
|
||||||
|
@ -42,6 +45,10 @@ impl fmt::Display for Error {
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
Error::UpgradeToTransaction => f.write_str("Cannot upgrade connection to transaction"),
|
Error::UpgradeToTransaction => f.write_str("Cannot upgrade connection to transaction"),
|
||||||
#[cfg(feature = "nightly")]
|
#[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"),
|
Error::CommitTransaction => f.write_str("Cannot commit changes of transaction"),
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
Error::RollbackTransaction => f.write_str("Cannot rolls transaction back"),
|
Error::RollbackTransaction => f.write_str("Cannot rolls transaction back"),
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl<'me> ConnectionClient for Transaction<'me> {
|
||||||
fn start_transaction(&mut self) -> crate::Result<Self::Trx<'_>> {
|
fn start_transaction(&mut self) -> crate::Result<Self::Trx<'_>> {
|
||||||
self.0
|
self.0
|
||||||
.transaction()
|
.transaction()
|
||||||
.map_err(|_| crate::Error::UpgradeToTransaction)
|
.map_err(|_| crate::Error::UpgradeToNestedTransaction)
|
||||||
.map(Transaction)
|
.map(Transaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,9 @@ impl<'me> ConnectionClient for Transaction<'me> {
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
fn start_transaction(&mut self) -> crate::Result<Self::Trx<'_>> {
|
fn start_transaction(&mut self) -> crate::Result<Self::Trx<'_>> {
|
||||||
// At the moment we cannot implement nested transaction because
|
// At the moment we cannot implement nested transaction because
|
||||||
// the transaction in `rusqlite` requires DerefMut, which cannot be
|
// the transaction in `rusqlite` 😣 We need to implement
|
||||||
// implemented yet 😣
|
// our box for transaction if we want to use it here.
|
||||||
unimplemented!()
|
Err(crate::Error::UpgradeToNestedTransaction)
|
||||||
// self.0
|
// self.0
|
||||||
// .transaction()
|
// .transaction()
|
||||||
// .map_err(|_| error::PersistenceError::UpgradeToTransaction)
|
// .map_err(|_| error::PersistenceError::UpgradeToTransaction)
|
||||||
|
|
Reference in a new issue