Live data from Hacker News

Sqlc: Compile SQL to type-safe code

sqlc.dev

31–40 of 109 posts

Re: Sqlc: Compile SQL to type-safe code

#31
post #2

Have been enjoying go-jet that takes a different approach: analyzes the tables in your DB and generates a set of Golang structs that lets you write 100% Golang code that looks like 99% SQL. Genius! https://github.com/go-jet/jet

There’s nothing unique about go-jet. Jooq does the same thing for example.

Re: Sqlc: Compile SQL to type-safe code

#32
post #2

Have been enjoying go-jet that takes a different approach: analyzes the tables in your DB and generates a set of Golang structs that lets you write 100% Golang code that looks like 99% SQL. Genius! https://github.com/go-jet/jet

There’s nothing unique about go-jet. Jooq does the same thing for example.

Jooq is amazing.

Re: Sqlc: Compile SQL to type-safe code

#33
post #2

Have been enjoying go-jet that takes a different approach: analyzes the tables in your DB and generates a set of Golang structs that lets you write 100% Golang code that looks like 99% SQL. Genius! https://github.com/go-jet/jet

Oh, so it's jOOQ but for Go. Nice. Sadly it does not support most custom Postgres things.

Supports COPY and pipelining, and all custom data types. I very rarely need to drop out of sqlc-generated code. What else could you want?

Re: Sqlc: Compile SQL to type-safe code

#34
post #25
post #2

Have been enjoying go-jet that takes a different approach: analyzes the tables in your DB and generates a set of Golang structs that lets you write 100% Golang code that looks like 99% SQL. Genius! https://github.com/go-jet/jet

Interesting. What happens if your schema is rolled back (e.g., to remove a new column), but your binary isn’t? Or is the idea to always deploy schema rollbacks alongside your binary? Edit: Also, curious about how this would work with a progressive schema rollout across environments - e.g., staging vs. prod DB. Do you need to “wait” for your new column to hit prod before you can use it in unit tests?

At a basic level - database migrations must be backwards compatible at least with the previous version, and they go out before the service update is deployed.

Unit tests don't run direct against prod usually, but regardless they would be run after migrations to a database of (production schema+migrations). Each environment - dev, test, staging, prod has its own db. Even spinning up an ephemeral db per test is possible, and easy with containers.

YMMV as system complexity increases, but by then there should be whole team(s) managing the issue

Re: Sqlc: Compile SQL to type-safe code

#35
post #2

Have been enjoying go-jet that takes a different approach: analyzes the tables in your DB and generates a set of Golang structs that lets you write 100% Golang code that looks like 99% SQL. Genius! https://github.com/go-jet/jet

+1 for go-jet. I came from python and sqlalchemy, where I used the declarative form to generate dynamic SQL (vs using the ORM, since I am fine with SQL) and go-jet allows me to do something similar in Go.

I wish go-jet would also start supporting duckdb, since I am exploring more local-first DB apps using sqlite, with duckdb as the query engine.

Re: Sqlc: Compile SQL to type-safe code

#36
post #2

Have been enjoying go-jet that takes a different approach: analyzes the tables in your DB and generates a set of Golang structs that lets you write 100% Golang code that looks like 99% SQL. Genius! https://github.com/go-jet/jet

There’s nothing unique about go-jet. Jooq does the same thing for example.

[deleted]

Re: Sqlc: Compile SQL to type-safe code

#37
post #12

Sort of related in this space I'd like to plug a related tool "sqlcode" that is a different approach to how to deploy stored procedures. Could be a nice partner to sqlc I think. Focused on mssql support so far though, and still a bit in beta/inhouse stage. https://github.com/vippsas/sqlcode

Looks nice! In case anyone is interested in a MySQL/MariaDB alternative, my tool Skeema can give a similar Git-friendly deploy flow for stored procedures, with all definitions tested in a temporary schema automatically so that any syntax errors are caught early before touching prod. Skeema was originally designed for declarative management of tables, but it can optionally be configured to only operate on procs/funcs if desired.

Approach-wise, I've always felt that traditional imperative migration tools are an especially bad fit for stored procedures. I wrote a post about this a little while back: https://www.skeema.io/blog/2023/10/24/stored-proc-deployment...

Re: Sqlc: Compile SQL to type-safe code

#38
post #2

Have been enjoying go-jet that takes a different approach: analyzes the tables in your DB and generates a set of Golang structs that lets you write 100% Golang code that looks like 99% SQL. Genius! https://github.com/go-jet/jet

JET doesn't support typesafe result mapping, or typesafe table joins, I believe. And it's not possible to do that in Go without some heavy-handed code generation. A better comparison is probably Hibernate and QueryDSL in Java.

Re: Sqlc: Compile SQL to type-safe code

#40
post #3

I've been looking into sqlc lately for Go. Seems brilliant except for the lack of dynamic queries: https://github.com/sqlc-dev/sqlc/discussions/364

You want Jet [0], as mentioned in another comment. I did an extensive survey of golang SQL interfacing libraries before settling on Jet for our team. It's certainly not without warts, but it's got the correct type of API (query builder that maps directly to SQL) and the struct mapping is pretty flexible. sqlc lacking support for dynamic query generation is just absolutely baffling. Composition of query fragments is,…

> try mapping postgres arrays or jsonb documents into structs and you'll see what I mean

I ended up adding custom value types to wrap our JSON (actually Protobuf) values: https://gist.github.com/Cyberax/07486a2264e29d95ed8c67e002f9... - we codegenerate them from Protobuf descriptions.

Post reply on HN