Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
1–10 of 44 posts
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#2bun-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.
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#3Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#4Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#5Can you make it work/ does it work with Porsager-Postgres in modnes which buns Postgres client is «based on»?
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#6Any 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?
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#7Support for postgis?
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
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#8Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#9Nice 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?