better transaction handling with rollback on exception

This commit is contained in:
azivner
2017-10-29 18:50:28 -04:00
parent afadd6ec06
commit de3d1b3e39
8 changed files with 145 additions and 150 deletions

View File

@@ -109,6 +109,21 @@ async function deleteRecentAudits(category, req, noteId) {
[category, browserId, noteId, deleteCutoff])
}
async function doInTransaction(func) {
try {
await beginTransaction();
await func();
await commit();
}
catch (e) {
log.error("Error executing transaction, executing rollback. Inner exception: " + e.stack);
await rollback();
}
}
module.exports = {
insert,
getSingleResult,
@@ -118,10 +133,8 @@ module.exports = {
executeScript,
getOption,
setOption,
beginTransaction,
commit,
rollback,
addAudit,
deleteRecentAudits,
remove
remove,
doInTransaction
};