// the find
gajus/slonik
A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.
Slonik is a PostgreSQL client for Node.js that enforces parameterized queries at the API level — you literally cannot pass a raw string to execute. It sits on top of the `pg` driver and adds typed query helpers (`one`, `many`, `maybeOne`, etc.) that throw named errors on constraint violations, plus Zod-based runtime validation of result shapes.
The forced `sql` tagged template literal API makes SQL injection a build-time error, not a code review concern. The semantic query methods (`oneFirst`, `maybeOne`) eliminate the boilerplate of checking rowCount everywhere and give you typed errors you can actually catch by name. The interceptor system is clean — query logging, field name transformation, and caching are all separate packages that hook in without patching the core. Zod integration for result validation catches schema drift at runtime rather than silently handing you `undefined` fields.
The monorepo has accumulated a lot of surface area — you now need `slonik`, `@slonik/pg-driver`, and whatever interceptors you want just to get a working pool, which is friction that `pg` or `postgres` don't impose. The `DISCARD ALL` on every connection release is documented as a 'heavy operation' and requires manual opt-out, which will surprise anyone running this against a high-concurrency workload without reading the fine print. There is no first-class migration story — you're pointed at external tools, which is fine, but means Slonik alone doesn't get you to production. The ecosystem packages (interceptors, dataloaders) vary in maintenance activity and some have thin documentation.