eslint: add no-shadow
This commit is contained in:
+10
-10
@@ -45,17 +45,17 @@ async function transaction(queries) {
|
||||
try {
|
||||
await connection.beginTransaction();
|
||||
const results = [];
|
||||
for (const query of queries) {
|
||||
const [rows /*, fields */] = await connection.query(query.query, query.args);
|
||||
for (const queryItem of queries) {
|
||||
const [rows /*, fields */] = await connection.query(queryItem.query, queryItem.args);
|
||||
results.push(rows);
|
||||
}
|
||||
await connection.commit();
|
||||
connection.release(); // no await!
|
||||
return results;
|
||||
} catch (error) {
|
||||
} catch (txError) {
|
||||
await safe(connection.rollback(), { debug });
|
||||
connection.release(); // no await!
|
||||
throw new BoxError(BoxError.DATABASE_ERROR, error, { sqlCode: error.code, sqlMessage: error.sqlMessage || null });
|
||||
throw new BoxError(BoxError.DATABASE_ERROR, txError, { sqlCode: txError.code, sqlMessage: txError.sqlMessage || null });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,20 +118,20 @@ async function runInTransaction(callback) {
|
||||
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 });
|
||||
const queryFn = async (...args) => {
|
||||
const [queryError, result] = await safe(connection.query(...args)); // this is same as getConnection/query/release
|
||||
if (queryError) throw new BoxError(BoxError.DATABASE_ERROR, queryError, { sqlCode: queryError.code, sqlMessage: queryError.sqlMessage || null });
|
||||
return result[0]; // the promise version returns a tuple of [rows, fields]
|
||||
};
|
||||
|
||||
const result = await callback(query);
|
||||
const result = await callback(queryFn);
|
||||
await connection.commit();
|
||||
connection.release(); // no await!
|
||||
return result;
|
||||
} catch (error) {
|
||||
} catch (txError) {
|
||||
await safe(connection.rollback(), { debug });
|
||||
connection.release(); // no await!
|
||||
throw new BoxError(BoxError.DATABASE_ERROR, error, { sqlCode: error.code, sqlMessage: error.sqlMessage || null });
|
||||
throw new BoxError(BoxError.DATABASE_ERROR, txError, { sqlCode: txError.code, sqlMessage: txError.sqlMessage || null });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user