integrity: add integrity check fields and initial UI

This commit is contained in:
Girish Ramakrishnan
2026-02-08 11:17:27 +01:00
parent 6303602323
commit 5276321ade
13 changed files with 232 additions and 50 deletions
+27
View File
@@ -5,6 +5,7 @@ exports = module.exports = {
uninitialize,
query,
transaction,
runInTransaction,
importFromFile,
exportToFile,
@@ -120,6 +121,32 @@ async function transaction(queries) {
}
}
async function runInTransaction(callback) {
assert.strictEqual(typeof callback, 'function');
const [error, connection] = await safe(gConnectionPool.getConnection());
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error, { sqlCode: error.code, sqlMessage: error.sqlMessage });
try {
await connection.beginTransaction();
const query = async (...args) => {
const [error, result] = await safe(connection.query(...args)); // this is same as getConnection/query/release
if (error) throw new BoxError(BoxError.DATABASE_ERROR, error, { sqlCode: error.code, sqlMessage: error.sqlMessage || null });
return result[0]; // the promise version returns a tuple of [rows, fields]
};
const result = await callback(query);
await connection.commit();
connection.release(); // no await!
return result;
} catch (error) {
await safe(connection.rollback(), { debug });
connection.release(); // no await!
throw new BoxError(BoxError.DATABASE_ERROR, error, { sqlCode: error.code, sqlMessage: error.sqlMessage || null });
}
}
async function importFromFile(file) {
assert.strictEqual(typeof file, 'string');