mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-20 22:16:52 +00:00
Improve manual transaction handling
Thanks @hoelzro
This commit is contained in:
parent
343cc33bbe
commit
d5aa74d9af
@ -500,7 +500,7 @@ SqlTiddlerDatabase.prototype.getRecipeBags = function(recipename) {
|
||||
/*
|
||||
Execute the given function in a transaction, committing if successful but rolling back if an error occurs. Returns whatever the given function returns.
|
||||
|
||||
Calls to this function can be safely nested, but only the top-most call will actually take place in a transaction.
|
||||
Calls to this function can be safely nested, but only the topmost call will actually take place in a transaction.
|
||||
*/
|
||||
SqlTiddlerDatabase.prototype.transaction = function(fn) {
|
||||
const alreadyInTransaction = this.transactionDepth > 0;
|
||||
@ -508,12 +508,13 @@ SqlTiddlerDatabase.prototype.transaction = function(fn) {
|
||||
if(alreadyInTransaction) {
|
||||
return fn();
|
||||
} else {
|
||||
this.runStatement(`BEGIN TRANSACTION`);
|
||||
try {
|
||||
this.runStatement(`BEGIN TRANSACTION`);
|
||||
var result = fn();
|
||||
this.runStatement(`COMMIT TRANSACTION`);
|
||||
} catch(e) {
|
||||
this.runStatement(`ROLLBACK TRANSACTION`);
|
||||
throw(e);
|
||||
} finally {
|
||||
this.transactionDepth--;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user