| ▲ | ilbert 5 hours 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 4 hours ago | parent | next [-] | ||||||||||||||||
Can you describe how it's the same and how it's different than SQLx (a Rust thing)? | |||||||||||||||||
| |||||||||||||||||
| ▲ | Retr0id 3 hours ago | parent | prev [-] | ||||||||||||||||
> silently drifts > genuinely > I'd mostly like to hear where it falls over. | |||||||||||||||||