13 comments

[ 2.7 ms ] story [ 38.0 ms ] thread
So, basically sqlc for Gleam? Sounds nice.

I wonder how Gleam compares to the type checking support being added to Elixir?

I'm a big fan of sqlc (which this is essentially a port of), so this is great to see.

I think the sqlc approach is ultimately the right one for integrating SQL into code because it allows queries to be expressed using the full syntax of native SQL, and only needs to handle the input/output glue. So you get the best of both worlds: Pure SQL unencumbered by non-SQL code, and type safety. ORMs will always struggle to catch up with SQL's richness and expressiveness.

I've not used Gleam for anything yet, but this makes me more excited to try it out.

The problem with sqlc is dynamic queries (mostly dynamic filters and ordering, which don't really affect type safety of the parameter or result-set mappings).

Even after years, the solutions are unsatisfactory from a database query planner perspective.

The best query builder I’ve seen is Kysely and it works because of anonymous sum types. So far no other library in any other language has come remotely close. You’d think Rust would have that level of type safety, but alas no.
sqlc always seemed like a really neat concept to me. I love the idea of being able to write my queries as raw SQL in separate files, would make everything so much more interoperable with other tools. Having your queries defined as strings inside some other programming language always struck me as not so awesome.

I'd love to see something like this for Typescript and Effect's SQL integration with schemas.

SQL is barely parametrizable, so, in my opinion, the DX is much worse than using a query builder and not much better than simply using strings.
Nice!

It reminds me of Jooq in Java-land. Does Parrot also try to fill-in the gaps in support between databases so that the same query works on all databases?

These sqlc-style libraries are a great solution to the problem of “make running a query as easy as calling a function”, but I’ve always thought SQL’s lack of composability is a more interesting problem that I haven’t seen addressed (the problems with views are well documented).
This looks really cool, but heads up, there were no up front descriptions or links I could follow to find out what Gleam is (a programming language that runs on the Erlang VM).