Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • Support for postgis?
  • 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

  • pretty neat, what's the technical reason it has to be Bun only?
  • No real reason, I was working with Bun's SQL module for a project and felt the need for such codegen. I'm thinking of generalizing it to Node.js
  • Kysely rules
  • Kysely is really cool, but I don't like that you are not writing SQL directly
  • sqlc is worth a mention.

    https://sqlc.dev

  • This looks great. I love using pgtyped, but have missed a solution that works well for sqlite.
  • Can you make it work/ does it work with Porsager-Postgres in modnes which buns Postgres client is «based on»?
  • 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?
  • 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?

  • 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.
  • have a look at https://sqlfu.dev - if you're using sqlite especially this likely has what you're looking for

    (disclaimer: i made sqlfu! and it's pretty early so use with appropriate caution. there's very little to the runtime part of it though, just very thin adapters around battle-tested clients)

  • 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
  • I don’t understand why no one is making SQL a first class citizen in a language, there are tons of languages out there that are extendable, how hard can it be, enough of DSL and generated type-safe application code which is a DSL in reverse order.
  • Microsoft has been doing this for a long time: https://learn.microsoft.com/en-us/dotnet/csharp/linq/
  • We built something quite similar - a full SQL framework with migrations, schema diffing, type-generation (this is the similar part I think), and named queries along with observability and more: https://sqlfu.dev

    It also ships adapters for pretty much all platforms, for sqlite at least: bun, node, libsql, better-sqlite3, expo-sqlite, sqlite-wasm, etc. etc.

    github: https://github.com/iterate/sqlfu

  • Really cool! I see you don't discover the SQL in the code right?
  • This is cool, but when the very first paragraph of the readme is clearly LLM generated, it makes me doubt the quality of the project.
  • you can review the code and decide if the quality is up to par?
  • Yeah, I'm still iterating on the docs
  • I've updated the READMEs by the way
  • LLM generated docs/readmes are at this point old news.
  • Those looking for a more mature solution in this space will probably enjoy SQLc [1]. It was initially developed for Go applications, but over the years it got pluggins for many other languages, including JavaScript/Typescript.

    [1] https://sqlc.dev/

  • And sqlx on the Rust side just for completeness
  • Also SQLDelight for Kotlin: https://sqldelight.github.io/sqldelight/
  • I love sqlc, but I think it's more fair to say it's an SQL code generator for Postgres and Go. Everything else is much less well-supported. You can pretty much forget about trying to use it with ClickHouse or SQLite, for example.

    It's also a project that seems to be suffering a bit from maintainer burnout. Important bugs aren't being fixed and contributor PRs aren't being merged. It took months to merge support for the new "\restrict" syntax introduced in Postgres 17's SQL schema dump format, for example.

  • It may be a good choice for golang, but support for other languages is not as great.

    I remember creating a PR [1] for some very obvious issues with Typescript generator for better-sqlite3 some two years ago which never received any attention from maintainers. There are bunch of such PRs languishing in obscurity in their repos.

    [1] https://github.com/sqlc-dev/sqlc-gen-typescript/pull/45