postgres.js
A fast, thin PostgreSQL client for Node.js using tagged template queries and simple connection pooling.
Official Documentation ↗v4.0.0. Check the official docs for the latest API surface.Installation
npm install postgresMethods
No methods match this filter.
postgres.js uses tagged template literals to build parameterized queries and pools connections automatically.
Key Features
- Tagged template queries with automatic parameterization
- Automatic connection pooling
- Listen/notify and COPY support
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/porsager/postgres@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:47.353Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- A cursor canceled while its callback runs, or while an async iterator over it is between batches, is stopped by the client instead: it fetches no more rows, closes its portal and rejects with 57014, with no cancel request sent. (https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md)
- A query that runs out of time is canceled as .cancel() would, and rejects with QUERY_TIMEOUT, with the 57014 it was canceled with as its cause. (https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md)
- As nobody knows whether the queries on that connection ran, they reject with CONNECTION_DESTROYED, or a timed out one with QUERY_TIMEOUT, whose cause is CANCEL_UNANSWERED. (https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:47.353Z.
- The parameters are then sent separately to the database which handles escaping & casting. (https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md)
- Query parameters Parameters are automatically extracted and handled by the database so that SQL injection isn’t possible. (https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md)
- Please note that this can lead to SQL injection if you’re not careful. (https://cdn.jsdelivr.net/gh/porsager/postgres@latest/README.md)
FAQ
- Is the tagged template safe from SQL injection?
- Yes. Interpolated values become bound parameters, so sql`... ${value}` is safe, but you must never build the query string manually.
- Does it support connection pooling?
- Yes. A single sql instance pools connections and reuses them; do not create one instance per request.
- How do I use transactions?
- Call sql.begin(async (sql) => { ... }) to run a callback inside a transaction, rolling back if it throws.
Report a problem with this API docOpens a pre-filled issue on GitHub.