pg-transactional-outbox
Version:
A PostgreSQL based transactional outbox and inbox pattern implementation to support exactly once message processing (with at least once message delivery).
24 lines • 935 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPgSerializationError = exports.releaseIfPoolClient = void 0;
const pg_1 = require("pg");
/** Check if it is a pool client to correctly release it */
const releaseIfPoolClient = (client, err) => {
if (client instanceof pg_1.Client && 'release' in client) {
client.release(err);
}
};
exports.releaseIfPoolClient = releaseIfPoolClient;
/** Check if the given error is based on a PostgreSQL serialization or deadlock error. */
const isPgSerializationError = (error) => {
if (error &&
typeof error === 'object' &&
'code' in error &&
// Trx Rollback: serialization failure = 40001 deadlock detected = 40P01
(error.code === '40001' || error.code === '40P01')) {
return true;
}
return false;
};
exports.isPgSerializationError = isPgSerializationError;
//# sourceMappingURL=database.js.map