API Reference

Slonik

PostgreSQL client for Node.js with strict typing, connection pooling, and a tagged template query API.

Official Documentation ↗
CompatibilityThis documentation covers version v49.12.0. Check the official docs for the latest API surface.

Installation

npmnpm install slonik

Methods

Slonik enforces parameterization and query normalization through sql tagged templates and typed results.

Key Features

  • Strict SQL tag with no raw interpolation
  • Pool with per-query timeouts
  • Runtime result validation via zod

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/gajus/slonik@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:39.153Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/gajus/slonik@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:39.153Z.

FAQ

Why does Slonik reject interpolation?
It requires explicit sql.identifier, sql.join, or sql.literal so that identifier and value handling stays safe and predictable.
How do I run multiple statements?
Use pool.transaction to wrap several queries in a transaction; callbacks are retried only when you opt into that behavior.
What are interceptors?
Middleware around queries for logging, timing, and type parsing; register them through the pool configuration.