gajus/slonik
View on GitHub ↗ ★ 4,937 TypeScript
A Node.js PostgreSQL client with runtime and build time type safety, and composable SQL.
39 mentions on Hacker News by 24 people: 4 stories, 35 comments · first 2019-01-30 · latest 2026-02-21
20082026
-
Slonik uses template strings to do this inline, safely. https://github.com/gajus/slonik
comment by Latty · 2026-02-21 · in Show HN: Pg-typesafe – Strongly typed queries for PostgreSQL and TypeScript -
…fragment literals in the caller programming language, like sql`name = ${name}` in TypeScript (eg https://github.com/gajus/slonik ). These are usually thin abstraction over concatenating a `{ queryText: string[], queryArgs: T[] }`…
comment by jitl · 2025-10-05 · in Parrot – type-safe SQL in Gleam, supports SQlite, PostgreSQL and MySQL -
Zod is the default validator for https://github.com/gajus/slonik . Zod alone accounts for a significant portion of the CPU time.
comment by gajus · 2025-04-12 · in ArkType: Ergonomic TS validator 100x faster than Zod -
There is Slonik [1] for instance. [1] https://github.com/gajus/slonik
comment by s4i · 2024-12-06 · in Litdb – type safe SQL for JavaScript/TS -
Didn’t use myself, but AFAIK slonik library is doing what you’ve described: https://github.com/gajus/slonik
comment by user432678 · 2024-09-10 · in Sqlc: Compile SQL to type-safe code -
…so that you can't accidentally pass in a normal string-interpolated string. Examples: - slonik: https://github.com/gajus/slonik?tab=readme-ov-file#protectin... - postgres.js: https://github.com/porsager/postgres?tab=readme-ov-file#quer...
comment by hombre_fatal · 2024-08-10 · in PEP 750: Tag Strings for Writing Domain-Specific Languages -
You can already use postgres with Slonik. https://github.com/gajus/slonik#user-content-slonik-how-are-... It is not going to be the default because it is way slower. https://github.com/gajus/slonik/actions/runs/6616647651 Test…
comment by gajus · 2023-10-23 · in PostgresJs: PostgreSQL client for Node.js and Deno -
Also see: https://github.com/gajus/slonik
comment by sheaton · 2023-10-14 · in PostgresJs: PostgreSQL client for Node.js and Deno -
…* FROM foo WHERE bar = \{inputParam}") which is exactly what many NodeJS libraries due, e.g. Slonik https://github.com/gajus/slonik , like sql`SELECT * FROM foo WHERE bar = ${inputParam}`;
comment by hn_throwaway_99 · 2023-09-25 · in JEP Draft: String Templates (Final) -
…it's necessary to use Zod/runtime validation everywhere, but it's a nice tool to have on hand. [1] https://github.com/gajus/slonik
comment by mavbo · 2023-09-15 · in We use TypeScript not based on preference, but because we want to make money -
…and accidentally one can make an SQL injection with these: https://github.com/porsager/postgres https://github.com/gajus/slonik
comment by ttfkam · 2023-06-29 · in Is ORM still an anti-pattern? -
Have you tried Slonik ( https://github.com/gajus/slonik )? It won't generate types from queries automatically, but it encourages writing SQL vs. a query builder and allows type annotations of queries with Zod. Query results are validated…
comment by mavbo · 2023-05-12 · in The Epic Stack -
Definitely a lot of misconceptions around how this would work. Just check out something like slonik, https://github.com/gajus/slonik , which is an excellent implementation. The example you gave actually isn't valid, because what you're…
comment by hn_throwaway_99 · 2023-03-09 · in JavaScript and TypeScript features of the last 3 years -
…Template strings in TypeScript allow you to safely write SQL directly, still with type checking: https://github.com/gajus/slonik#readme
comment by hn_throwaway_99 · 2023-01-25 · in Kysely: TypeScript SQL Query Builder -
…cool project but I do think query builders ARE generally an anti-pattern. I'm a huge fan of slonik, https://github.com/gajus/slonik#readme , which uses template strings for SQL and has recently come a long way with its strong typing…
comment by hn_throwaway_99 · 2023-01-25 · in Kysely: TypeScript SQL Query Builder -
Slonik comes pretty close https://github.com/gajus/slonik . It does not inspect your DB schema, but has worked very well in our SQL-heavy architecture.
comment by cheeseface · 2023-01-24 · in Kysely: TypeScript SQL Query Builder -
…use cases for runtime validation, namely when dealing with external inputs/databases, e.g. https://github.com/gajus/slonik#user-content-runtime-validat... Flow had [flow-runtime]( https://github.com/gajus/flow-runtime ), which was nice.…
comment by gajus · 2022-10-13 · in Hegel – An advanced static type checker for JavaScript -
…want is something like slonik which is more focused on querying than relational mapping. [0]: https://github.com/gajus/slonik
comment by hardwaresofton · 2022-09-29 · in Flyweight: An ORM for SQLite -
…develop Zapatos, but Slonik and pg-typed are probably better known. https://jawj.github.io/zapatos/ https://github.com/gajus/slonik https://pgtyped.vercel.app/
comment by gmac · 2022-06-28 · in SQLite or PostgreSQL? It's Complicated -
I've been a huge fan of Slonik, https://github.com/gajus/slonik , which makes it easy and safe to write direct SQL queries. The author of Slonik had a good article about the downsides of query builders, previously discussed on HN, that I…
comment by hn_throwaway_99 · 2021-11-26 · in Our journey in dropping the ORM in Go -
…, but a few years after I wrote that (and mostly didn't use it) I found https://github.com/gajus/slonik which was very similar and much more fleshed-out; I rolled _some_ of its concepts and patterns into sql-athame.
comment by phs2501 · 2021-08-27 · in Write an SQL query builder in 150 lines of Python -
In this space but a little lighter: https://github.com/gajus/slonik
comment by hardwaresofton · 2021-08-10 · in Show HN: Write universally accessible SQL, not library-specific ORM wrapper APIs -
https://github.com/gajus/slonik
comment by domlebo70 · 2021-04-21 · in Prisma – ORM for Node.js and TypeScript -
…topic for a different discussion. We have a set of DAO components that access the DB using Slonik, https://github.com/gajus/slonik (overview explaining the rationale for this library is at https://medium.com/@gajus/bf410349856c ). Our app…
comment by hn_throwaway_99 · 2021-04-20 · in Node.js 16 Available Now -
I like the idea and project goals. There are however gems like this in the source: https://github.com/gajus/slonik/blob/master/src/routines/exe... You can spend an hour trying to reason about the control flow of that triple try/catch…
comment by chmod775 · 2021-03-11 · in Slonik: A PostgreSQL client with strict types, detailed logging, and assertions -
On a related note, I've become a gigantic fan of Slonik, https://github.com/gajus/slonik , which simultaneously (a) makes it extremely difficult to expose SQL injection attacks while (b) still letting you write SQL in a very "natural" way…
comment by hn_throwaway_99 · 2021-03-02 · in Rookie coding mistake prior to Gab hack came from site’s CTO -
Specifically in Node.js, https://github.com/gajus/slonik has drastically improved the experience of writing and composing SQL queries. I am the author of Slonik.
comment by gajus · 2020-06-09 · in Prisma 2.0 – Type-safe and auto-generated database client -
How is it different from Slonik? https://github.com/gajus/slonik
comment by garrybelka · 2020-05-25 · in Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres -
…Another one in a similar vein with strict typing and really nice SQL interpolation for Postgres: https://github.com/gajus/slonik
comment by adriancooney · 2020-05-25 · in Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres -
…Froala - https://www.froala.com/wysiwyg-editor SequelizeJS - https://sequelize.org/master/ Slonik - https://github.com/gajus/slonik WS - https://github.com/websockets/ws Socket.io - https://socket.io/
comment by truth_seeker · 2019-09-10 · in Running GitHub on Rails 6.0 -
…check out `slonik` [0]. It doesn't support migrations, but there are other tools for that [1]. [0] https://github.com/gajus/slonik [1] https://github.com/mmkal/slonik-tools
comment by lhnz · 2019-09-10 · in Running GitHub on Rails 6.0