Initial content

This commit is contained in:
Adam Freeman
2024-05-29 18:54:49 +01:00
parent 2dbc1a8088
commit 5215a1d919
1944 changed files with 203378 additions and 0 deletions
@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionHelper = void 0;
class TransactionHelper {
steps = [];
add(sql, params) {
this.steps.push([sql, params]);
return this;
}
run(db) {
return new Promise((resolve, reject) => {
let index = 0;
let lastRow = NaN;
const cb = (err, rowID) => {
if (err) {
db.run("ROLLBACK", () => reject());
}
else {
lastRow = rowID ? rowID : lastRow;
if (++index === this.steps.length) {
db.run("COMMIT", () => resolve(lastRow));
}
else {
this.runStep(index, db, cb);
}
}
};
db.run("BEGIN", () => this.runStep(0, db, cb));
});
}
runStep(idx, db, cb) {
const [sql, params] = this.steps[idx];
db.run(sql, params, function (err) {
cb(err, this.lastID);
});
}
}
exports.TransactionHelper = TransactionHelper;