Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function commitAndRelease(connection, leased, cb) {
if (!connection || _.isFunction(connection)) {
return cb(new Error('Commit and Release requires a valid connection.'));
}
// Commit the transaction
PG.commitTransaction({
connection: connection
})
.exec(function commitCb(err) {
if (err) {
// Rollback the transaction
PG.rollbackTransaction({
connection: connection
})
.exec(function rollbackCb() {
// Only release the connection if it wasn't leased from outside the
// adapter.
if (leased) {
return cb(err);
}
// Release the connection back into the pool