Merge pull request #325 from rnewman/rnewman/panic

Add DropBehavior::Panic to enforce intentional commit or rollback.
This commit is contained in:
gwenn 2018-03-24 10:29:02 +01:00 committed by GitHub
commit d962ebab55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,9 @@ pub enum DropBehavior {
/// Do not commit or roll back changes - this will leave the transaction or savepoint /// Do not commit or roll back changes - this will leave the transaction or savepoint
/// open, so should be used with care. /// open, so should be used with care.
Ignore, Ignore,
/// Panic. Used to enforce intentional behavior during development.
Panic,
} }
/// Old name for `Transaction`. `SqliteTransaction` is deprecated. /// Old name for `Transaction`. `SqliteTransaction` is deprecated.
@ -195,6 +198,7 @@ impl<'conn> Transaction<'conn> {
DropBehavior::Commit => self.commit_(), DropBehavior::Commit => self.commit_(),
DropBehavior::Rollback => self.rollback_(), DropBehavior::Rollback => self.rollback_(),
DropBehavior::Ignore => Ok(()), DropBehavior::Ignore => Ok(()),
DropBehavior::Panic => panic!("Transaction dropped unexpectedly."),
} }
} }
} }
@ -306,6 +310,7 @@ impl<'conn> Savepoint<'conn> {
DropBehavior::Commit => self.commit_(), DropBehavior::Commit => self.commit_(),
DropBehavior::Rollback => self.rollback(), DropBehavior::Rollback => self.rollback(),
DropBehavior::Ignore => Ok(()), DropBehavior::Ignore => Ok(()),
DropBehavior::Panic => panic!("Savepoint dropped unexpectedly."),
} }
} }
} }