# @slonik/pg-driver

> A Node.js PostgreSQL client with strict types, detailed logging and assertions.

Latest version **49.13.0** (published 2026-11-06) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @slonik/pg-driver
pnpm add @slonik/pg-driver
yarn add @slonik/pg-driver
bun add @slonik/pg-driver
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 49.13.0 |
| Published | 2026-11-06 |
| First published | 2024-05-07 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=24 |
| Dependencies | 9 |
| Unpacked size | 48.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4939 |
| Author | Gajus Kuizinas |
| Maintainers | gajus |
| Keywords | postgresql, promise, types |

## Links

- npm: https://www.npmjs.com/package/@slonik/pg-driver
- Repository: https://github.com/gajus/slonik
- Homepage: https://github.com/gajus/slonik#readme
- Issues: https://github.com/gajus/slonik/issues
- npm.io page: https://npm.io/package/@slonik/pg-driver

## Dependencies (9)

- [pg](https://npm.io/package/pg.md) ^8.22.0
- [pg-types](https://npm.io/package/pg-types.md) ^4.1.0
- [@slonik/types](https://npm.io/package/@slonik/types.md) ^49.13.0
- [@slonik/driver](https://npm.io/package/@slonik/driver.md) ^49.13.0
- [@slonik/errors](https://npm.io/package/@slonik/errors.md) ^49.13.0
- [postgres-array](https://npm.io/package/postgres-array.md) ^3.0.4
- [@slonik/sql-tag](https://npm.io/package/@slonik/sql-tag.md) ^49.13.0
- [pg-query-stream](https://npm.io/package/pg-query-stream.md) ^4.12.0
- [@slonik/utilities](https://npm.io/package/@slonik/utilities.md) ^49.13.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 49.13.0 (latest) — 2026-11-06
- 49.12.0 — 2026-10-24
- 49.11.0 — 2026-10-11
- 49.10.10 — 2026-09-21
- 49.10.9 — 2026-07-26
- 49.10.8 — 2026-07-26
- 49.10.7 — 2026-06-16
- 49.10.6 — 2026-06-16
- 49.10.5 — 2026-06-16
- 49.10.4 — 2026-06-16
- 49.10.3 — 2026-06-16
- 49.10.1 — 2026-06-10
- 49.10.0 — 2026-06-05
- 49.9.0 — 2026-06-03
- 49.8.0 — 2026-05-29
- … 88 more at https://npm.io/package/@slonik/pg-driver/versions

## README

# Slonik Driver for `pg`

```ts
import { createPgDriverFactory, DatabaseError } from "@slonik/pg-driver";
```

## Error handling

All Slonik errors extend from `SlonikError`. `SlonikError` uses `cause` property to store the original error, which might be a `DatabaseError` from `pg`. Example:

```ts
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:

```ts
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.
    }
  }
});
```

---
_Source: https://npm.io/package/@slonik/pg-driver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
