SQLC + pgx for Production

Hi folks,

I’ve been using GORM for 1/2 years, but I keep seeing some people in the community talking about SQLC + SQLX and how good it is, I’m using this space to ask your experiences with it

Also, what tool you folks use for migrations?

I use SQLC and Goose.

Definetely Production ready. This does just help you with boiler plate.

Thus I do believe it is actually more production ready than gorm :sweat_smile:

I haven’t used them in production. But - I have a few thoughts. First off: I’m wondering why you would combine them? I generally want a few things to make my life easier when writing simple queries:

  • Queries to structs. Both SQLX and SQLC support this; though with SQLC you will need to add a select * from my_table to get it to generate the boilerplate. Also - pgx supports this without a 3rd party and I use that quite frequently.
  • Something to reduce boilerplate for simple CRUD operations. Again - both libraries support this.
  • Something to actually run my migrations and keep track of what was run. Neither libraries support this. I often roll my own because it’s honestly not rocket science. But there are many libraries out there for this.

Anyway, I’m wondering how you’re planning on combining them. They seem like two pretty opinionated tools that have similar goals.

Second: do we know how actively-maintained sqlx is? Check the repository out:

Last commit was 2 years ago. It seems the original maintainer is mostly gone. And there have been open pull requests hanging out for a while:

Something to consider! And just trying to get a feel for how you’re planning on using these libraries.

All that having been said, gorm gets a lot of hate but it’s plenty fast for simple CRUD operations in my experience. And anytime I’m doing something advanced, I invariably end up writing my own hand-tuned queries. So - gorm for simple stuff hand-written SQL for hard stuff isn’t a terrible way to go.

Also - like I mentioned, I often just “start with pgx” and end up needing not much else. They added utility functions to scan to structs by name, etc.:

I actually meant SQLC + pgx, not sure why I wrote SQLX lol, I’ll update the title

That said, I will give SQLC a try, with Goose for migrations, thank you folks @Karl @Dean_Davidson

Ahhh. That makes sense! Yeah - pgx is great and a no-brainer IMO. Especially if you need to do bulk imports of data (it supports COPY).

I’ve used goose. It’s OK. I generally prefer to use config files/env vars and it previously didn’t support that (it does now). Also - it’s supported by sqlc:

I mean I do not see any reason why SQL should be outdated soon.
This is constant since many years.

you can run savely a relatively old db version as well. Especially if you do not expose it directly.

What should change and break?

Even if you have an extreme edge case where your SQLC does not work. - Which is highly unlikely, then you have to write that one query by hand. :waving_hand: :sweat_smile:

Karl, I was noting that SQLX seems to not be actively maintained, not SQLC. :slight_smile:

1 Like