package
A Node.js PostgreSQL client with strict types, detailed logging and assertions.
npm install @slonik/pg-driverGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
pgimport { createPgDriverFactory, DatabaseError } from "@slonik/pg-driver";All Slonik errors extend from SlonikError. SlonikError uses cause property to store the original error, which might be a DatabaseError from pg. Example:
pool.on("error", (error) => {
const cause = error.cause;
if (cause instanceof DatabaseError) {
console.log(cause.code);
}
});This allows you to handle errors based on the lower-level error codes provided by pg driver.
Example of handling all errors that could warrant a fatal error:
const fatalErrorClasses = [
// Connection Exception
"08",
// Invalid Authorization Specification
"28",
];
pool.on("error", (error) => {
if (error.cause instanceof DatabaseError) {
const classCode = error.cause.code.slice(0, 2);
if (fatalErrorClasses.includes(classCode)) {
// Initiate shutdown due to unexpected connection state.
}
}
});Estimated unpacked size across 32 packages.
7.6 MB
Includes dependencies.
9 direct dependencies.
^8.22.0
8.23.1
^4.1.0
4.1.0
^49.13.0
49.13.0
^49.13.0
49.13.0
^49.13.0
49.13.0
^49.13.0
49.13.0