frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM

https://github.com/ilbertt/bun-sqlgen
27•ilbert•1h ago

Comments

ilbert•1h ago
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.

trollbridge•43m ago
Can you describe how it's the same and how it's different than SQLx (a Rust thing)?
ilbert•36m ago
I actually took a lot of inspiration from sqlx, which is really nice. The main differences are:

- in JS/TS you don't have compile-time scripts that you can run like with Rust's macros, so you need to run a codegen command before running the type checks (disadvantage)

- I had to create a TS parser that goes and finds the tagged template functions with the sql statements, while sqlx has them "for free" because sql statements are the input to the macro itself (disadvantage)

- I use an in-memory Postgres (PGLite) to describe the queries, instead of requiring a running pg instance (advantage)

- I don't cache the statements and codegen for now like sqlx does, something that can be added later

I think they are similar in that they both substitute the dynamic params with no-ops like $1, $2, etc. before handing the sql statement to the pg's DESCRIBE function

Retr0id•4m ago
> silently drifts

> genuinely

> I'd mostly like to hear where it falls over.

https://news.ycombinator.com/newsguidelines.html#generated

psc007•1h ago
Can you make it work/ does it work with Porsager-Postgres in modnes which buns Postgres client is «based on»?
ilbert•1h ago
I think with some tweaks to the TS parser that goes and looks for the sql statements it's doable. How are you solving the problem right now?
psc007•1h ago
Support for postgis?
ilbert•1h ago
The cli config supports specifying the PGLite extensions (the codegen uses PGLite as an in-memory light postgres), see this example: https://github.com/ilbertt/bun-sqlgen/tree/main/examples/wit....

You'll still probably have to manually override some column types using PG comments like: https://github.com/ilbertt/bun-sqlgen/blob/dee757ebc9c38aec7...

PGLite extensions: https://pglite.dev/extensions/#postgis

sHooKDT•1h ago
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?

ilbert•1h ago
I was targeting Bun because I really like its built-in SQL module. I can tweak the TS parser to look for e.g. postgres.js tagged template functions and make it work for that as well. I don't really see any blockers
tomComb•19m ago
Yes, bun is good locally, but need node support for deployment. So while the bun specific stuff sounds great I feel I need to avoid it.
danr4•1h ago
pretty cool
rankdiff•10m ago
sqlc is worth a mention.

https://sqlc.dev

Show HN: TikZ Editor – WYSIWYG editor for figures in LaTeX

https://tikz.dev/editor/
138•DominikPeters•1h ago•24 comments

Unlimited OCR: One-Shot Long-Horizon Parsing

https://github.com/baidu/Unlimited-OCR
279•ingve•4h ago•77 comments

Spying on kids to save kids from spying is stupid

https://pluralistic.net/2026/06/23/destroy-the-village/
263•hn_acker•2h ago•167 comments

Lift4D: Harmonizing Single-View 3D Estimation for 4D Reconstruction In-the-Wild

https://lift4d.github.io/
32•ilreb•1h ago•1 comments

Mistral OCR 4

https://mistral.ai/news/ocr-4/
173•meetpateltech•2h ago•48 comments

Five monitors on a Commodore 128 [video]

https://www.youtube.com/watch?v=ul5hC3PY1Yg
9•EvanAnderson•21h ago•0 comments

AI's Affordability Crisis

https://blog.dshr.org/2026/06/ais-affordability-crisis.html
88•ilreb•1h ago•80 comments

Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM

https://github.com/ilbertt/bun-sqlgen
27•ilbert•1h ago•13 comments

MSG Made Dossier on Activists Who Opposed Facial Recognition

https://www.404media.co/madison-square-garden-made-dossier-on-activists-who-opposed-facial-recogn...
141•cdrnsf•2h ago•28 comments

Plotnine

https://plotnine.org/
178•tosh•4d ago•57 comments

Open Source for IBM Z and LinuxONE

https://community.ibm.com/community/user/blogs/elizabeth-k-joseph1/2026/06/18/linuxone-open-sourc...
18•ncruces•3d ago•1 comments

Show HN: Treedocs: Documentation that automatically checks for staleness

https://dandylyons.github.io/treedocs/
13•DandyLyons•1h ago•7 comments

GLM-5.2 – How to Run Locally

https://unsloth.ai/docs/models/glm-5.2
522•TechTechTech•18h ago•248 comments

Lossless GIF recompression via exhaustive search

https://blog.arusekk.pl/posts/lossless-gif-recompression/
29•ZacnyLos•3h ago•3 comments

Will It Mythos?

https://swelljoe.com/post/will-it-mythos/
243•mindingnever•12h ago•180 comments

Crypto in 2026: Oh, This Is the Bad Place

https://www.stephendiehl.com/posts/bad_place_2026/
292•ibobev•6h ago•331 comments

VibeThinker: 3B param model that beats Opus 4.5 on reasoning with novel SFT+GRPO

https://arxiv.org/abs/2606.16140
309•timhigins•14h ago•165 comments

80386 Early Start Memory Access

https://nand2mario.github.io/posts/2026/80386_early_start/
17•nand2mario•3h ago•1 comments

Researchers used math to crack Wordle

https://www.binghamton.edu/news/story/6327/s-m-a-r-t-these-researchers-used-math-to-crack-wordle
21•hhs•2d ago•26 comments

Steam Machine launches today

https://store.steampowered.com/news/group/45479024/view/685257114654870245
1822•theschwa•23h ago•1556 comments

The Low-Tech AI of Elden Ring

https://nega.tv/posts/low-tech-ai-of-elden-ring.html
20•g0xA52A2A•4h ago•5 comments

Show HN: Neural Particle Automata

https://selforg-npa.github.io/
64•esychology•7h ago•14 comments

In praise of memcached

https://jchri.st/blog/in-praise-of-memcached/
236•j03b•15h ago•99 comments

The Traditional Vi

https://ex-vi.sourceforge.net/
50•exvi•7h ago•34 comments

Giant Banana Pulled Over: Driver Says Cops Have Stopped Him 100s of Times

https://cowboystatedaily.com/2026/06/18/giant-banana-pulled-over-in-montana-driver-says-cops-have...
167•speckx•2d ago•60 comments

Show HN: Shumai – open-source Frame.io alternative for creative work

https://github.com/shumaiOne/shumai
39•Yiling-J•6h ago•2 comments

Elevated error rate across multiple models

https://status.claude.com/incidents/jbhf20wjmzrf
163•rob•1h ago•186 comments

OpenAI DayBreak – GPT-5.5-Cyber

https://openai.com/index/daybreak-securing-the-world/
182•AaronO•14h ago•135 comments

8086 Segmented Memory was a good idea

https://owl.billpg.com/8086-segmented-memory-was-a-good-idea-almost/
54•billpg•2d ago•97 comments

My Mathematical Regression

https://blog.dahl.dev/posts/my-mathematical-regression/
342•aleda145•4d ago•134 comments