Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
ilbert
54 points
29 comments
June 23, 2026
Related Discussions
Found 5 related stories in 104.2ms across 11,417 title embeddings via pgvector HNSW
- Bun's rewrite in Rust was merged maxloh · 30 pts · May 14, 2026 · 56% similar
- Rewrite Bun in Rust has been merged Chaoses · 578 pts · May 14, 2026 · 53% similar
- Bun's Rust rewrite has been merged ale · 90 pts · May 14, 2026 · 53% similar
- Bun's unreleased Rust port has 13,365 unsafe blocks helloplanets · 51 pts · May 22, 2026 · 53% similar
- Show HN: Orch8 – Durable workflow engine in Rust, one binary, Postgres or SQLite _alphageek · 22 pts · May 05, 2026 · 52% similar
Discussion Highlights (12 comments)
ilbert
I write Bun.sql with raw SQL and no ORM, and the one thing I kept missing was types. You write a query, get back `any[]`, and hand-write a row type that silently drifts from the actual columns. Drizzle/Kysely fix this by moving the query into TypeScript, but then you're not really writing SQL anymore. bun-sqlgen goes the other way. You keep writing raw SQL queries, just give each one a name. A codegen step reads your migration `.sql` files, stands up a throwaway Postgres via PGlite (so no Docker) or SQLite, prepares every tagged query against it, and writes a `.d.ts` that maps each query name to its real result type. After that, plain `tsc` does the rest: `user.notExistingField` won't compile, and `display_name.length` gets flagged because the column is nullable. Nullability was the annoying part. Postgres's describe doesn't hand you per-column nullability, so I infer it from the query plan plus the catalog, with manual overrides for the cases that genuinely can't be inferred. SQLite works too. The runtime stays 100% Bun.sql, the generated file is the only artifact (commit it), and codegen is fast enough to rerun on save. It's early (v0.1, built it for my own projects) so I'd mostly like to hear where it falls over.
psc007
Can you make it work/ does it work with Porsager-Postgres in modnes which buns Postgres client is «based on»?
psc007
Support for postgis?
sHooKDT
Nice project, thanks! I was looking for something like that for quite a while. Any chance to get it to work with Node? Unfortunately in my opinion and experience Bun is not really suitable for production. Does it have anything special which makes this possible?
danr4
pretty cool
rankdiff
sqlc is worth a mention. https://sqlc.dev
genshii
This is cool, but when the very first paragraph of the readme is clearly LLM generated, it makes me doubt the quality of the project.
giovannibonetti
Those looking for a more mature solution in this space will probably enjoy SQLc [1]. It was initially developed for Go applications, but over the years it got pluggins for many other languages, including JavaScript/Typescript. [1] https://sqlc.dev/
allthetime
Kysely rules
zareith
This looks great. I love using pgtyped, but have missed a solution that works well for sqlite.
inline_always
pretty neat, what's the technical reason it has to be Bun only?
schultzer
I don’t understand why no one is making SQL a first class citizen in a language, there are tons of languages out there that are extendable, how hard can it be, enough of DSL and generated type-safe application code which is a DSL in reverse order.