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…
Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
11–20 of 44 posts
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#12I 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…
Can you describe how it's the same and how it's different than SQLx (a Rust thing)?
- 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
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#13Nice 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?
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#14Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#15I 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…
> genuinely
> I'd mostly like to hear where it falls over.
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#16Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#17Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#18This is cool, but when the very first paragraph of the readme is clearly LLM generated, it makes me doubt the quality of the project.
Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#19Re: Show HN: Bun-sqlgen – Type-safe raw SQL for Bun, no ORM
#20This is cool, but when the very first paragraph of the readme is clearly LLM generated, it makes me doubt the quality of the project.