integrity: add integrity check fields and initial UI
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user