Slonik
PostgreSQL client for Node.js with strict typing, connection pooling, and a tagged template query API.
Official Documentation ↗v49.12.0. Check the official docs for the latest API surface.Installation
npm install slonikMethods
No methods match this filter.
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.
- Using methods with inbuilt assertions ensures that in case of an error, the error points to the source of the problem. (https://cdn.jsdelivr.net/gh/gajus/slonik@latest/README.md)
- Furthermore, using methods that guarantee the shape of the results allows us to leverage static type checking and catch some of the errors even before executing the code, e.g. (https://cdn.jsdelivr.net/gh/gajus/slonik@latest/README.md)
- This error is thrown to prevent accidental unsafe transaction handling, e.g. (https://cdn.jsdelivr.net/gh/gajus/slonik@latest/README.md)
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.
- This security vulnerability is especially a significant risk in Node.js community, where a predominant number of developers are coming from frontend and have not had training working with RDBMSes. (https://cdn.jsdelivr.net/gh/gajus/slonik@latest/README.md)
- To sum up, Slonik is designed to prevent accidental creation of queries vulnerable to SQL injections. (https://cdn.jsdelivr.net/gh/gajus/slonik@latest/README.md)
- This is a security measure designed to prevent unsafe query execution. (https://cdn.jsdelivr.net/gh/gajus/slonik@latest/README.md)
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.