Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.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
PG.releaseConnection({
connection: connection
})
.exec(function releaseCb() {
return cb(err);
});
module.exports = function rollbackAndRelease(connection, leased, cb) {
if (!connection || _.isFunction(connection)) {
return cb(new Error('Commit and Release requires a valid connection.'));
}
// Rollback the transaction
PG.rollbackTransaction({
connection: connection
})
.exec(function rollbackCb() {
// Only release the connection if the leased flag is false
if (leased) {
return cb();
}
// Release the connection back into the pool
PG.releaseConnection({
connection: connection
})
.exec(function releaseCb() {
return cb();
});
});