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
20•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•22m ago
Can you describe how it's the same and how it's different than SQLx (a Rust thing)?
ilbert•15m 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

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•48m 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
danr4•52m ago
pretty cool

Factory job cuts in June neared financial crisis and Covid levels, S&P says

https://www.cnbc.com/2026/06/23/factory-job-cuts-reported-around-financial-crisis-and-covid-level...
1•toomuchtodo•1m ago•1 comments

Ask HN: Best prompt to show that AI isn't ready to take over

1•AndrewSwift•1m ago•0 comments

Show HN: Mirrorball – easy port forwarding for remote dev hosts

https://mirrorball.sanil.co/
2•sanil•4m ago•0 comments

Netflix's video podcast engagement numbers 'are low,' per insider

https://awfulannouncing.com/netflix/video-podcast-engagement-numbers-are-low-matthew-belloni.html
2•Vaslo•4m ago•0 comments

Ask HN: When should we expect DNS-persist-01 in production?

2•cromka•4m ago•0 comments

Show HN: Get lead and research lists from one search

https://sensecollect.com
2•chrislxy•4m ago•0 comments

Beehiiv adds Cloudflare AI Crawl Control so writers can block or allow bots

https://siliconangle.com/2026/06/23/beehiiv-adds-cloudflare-ai-crawl-control-writers-can-block-al...
2•ilreb•5m ago•0 comments

Designing an App Icon That Feels Like an Album Cover

https://rajavijayaraman.com/writing/designing-an-app-icon-that-feels-like-an-album-cover/
2•rajavijayaraman•5m ago•0 comments

Show HN

https://matchups.live/
2•uxmeekkow•6m ago•0 comments

Doctors Thought It Was Asthma. A.I. Flagged a Serious Heart Problem

https://www.nytimes.com/2026/06/22/health/artificial-intelligence-heart-damage.html
2•brandonb•6m ago•0 comments

Private Orchards – Practical iPhone Privacy and Security Guides

https://privateorchards.com/
2•PrivateOrchards•8m ago•0 comments

I turned World Cup data into posters

https://zehfernandes.com/posts/how-i-turned-world-cup-data-into-posters
2•plurby•8m ago•0 comments

Onsubmit.dev

https://onsubmit.dev
2•ekwoster•8m ago•0 comments

Show HN: Wype – Strip GPS, timestamps, and device models from your files

https://wype.onrender.com
2•achlyssecurity•9m ago•0 comments

Cargo Culture

https://www.wheresyoured.at/cargo-culture/
2•crescit_eundo•9m ago•0 comments

Seedance 2.5

https://seedance2.ai/seedance-2-5
4•bytegogogo•9m ago•0 comments

Study of niacin (vitamin B3) in patients with newly diagnosed glioblastoma

https://link.springer.com/article/10.1007/s11060-025-05351-z
3•bookofjoe•10m ago•0 comments

Shopify replaced Redis with MySQL for inventory reservations–and it scaled

https://shopify.engineering/scaling-inventory-reservations
2•ohjeez•11m ago•0 comments

Show HN: Snowscroll – I removed addictive feeds from social media

https://snowscroll.com/
2•junnam586•11m ago•0 comments

You Cannot Grow a Pumpkin

https://taylor.town/pumpkin
2•surprisetalk•13m ago•0 comments

Using Elasticsearch Percolate for User Notifications

https://acv.engineering/posts/elasticsearch-percolate/
2•mooreds•14m ago•0 comments

The unlikely upside to age-gating

https://reedandpickup.com/2026/06/17/the-unlikely-upside-to-agegating.html
2•speckx•14m ago•0 comments

Toward More Controllable AI Video Editing: Research Exploration at Netflix

https://netflixtechblog.com/toward-more-controllable-ai-video-editing-an-early-research-explorati...
2•MattSayar•17m ago•0 comments

Meta launches cheaper smart glasses without Ray-Ban

https://www.theverge.com/tech/954052/meta-glasses-hands-on-kylie-jenner-smart-glasses-price-batte...
3•dkobia•17m ago•1 comments

Walmart to Acquire Vibe.co to Expand Access to Connected TV Advertising

https://corporate.walmart.com/news/2026/06/23/walmart-to-acquire-vibe-co-to-expand-access-to-conn...
3•pil0u•17m ago•0 comments

Are AI and robotics about to free the wealthy from the threat of revolt?

https://morbidcuriosity.substack.com/p/the-age-of-bunker-capitalism
2•pnwpnw•18m ago•0 comments

Why developers use LLMs to write blog posts

https://writethatblog.substack.com/p/report-llms-tech-blogs
3•cyndunlop•18m ago•2 comments

How 2 Designers ditched Figma (sort of) to rebuild a marketing site

https://buildwithfern.com/post/building-fern-site
5•theanswa•18m ago•1 comments

The Supabase of Animation – MotionScript.dev

https://www.motionscript.dev/
3•kevinoliveira•18m ago•1 comments

Latin America just elected its fifth right-wing president in a row

https://respublica.media/en/five-elections-seven-months-latin-americas-right-turn/
2•Veldoran•19m ago•0 comments