ap / DBIx-Connector

Fast, safe DBI connection and transaction management
https://metacpan.org/release/DBIx-Connector
40 stars 14 forks source link

Add Sentinel Pattern #35

Open theory opened 11 years ago

theory commented 11 years ago

Lost of folks have asked for this, and I recently ran into a place or two where I would have found it useful. The idea is to get an object that can be held onto and used for stuff, and until it goes out of scope, it would keep a transaction open.

ap commented 2 years ago

How does it know whether to commit or roll back in DESTROY?

theory commented 2 years ago

You'd have to ask mst I think, he was the biggest advocate for it

ap commented 2 years ago

Pinging @shadowcat-mst then…

shadowcat-mst commented 2 years ago

Roll back and preferably warn unless already explicitly committed or rolled back. The way TxnScopeGuard works in DBIC is that.

The reasoning for this is that if you did neither, your code almost certainly contains a bug - either you forgot to commit/rollback entirely or you're exiting the scope due to an exception being thrown that you didn't have code to catch.

Behaving this way is occasionally annoying, but maximises safety, and if you didn't want to maximise safety, well, you know where MyISAM is ;)

theory commented 2 years ago

LOL throwing in the MyISAM put-down for us olds, well done! 😂