How We Went All In on sqlc/pgx for Postgres and Go
1–10 of 160 posts
Re: How We Went All In on sqlc/pgx for Postgres and Go
#2Re: How We Went All In on sqlc/pgx for Postgres and Go
#3It uses the official postgres parser to know all the types of your tables and queries, and can generate perfect Go structs from this.
It even knows your table and field types just from reading your migrations, tracking changes perfectly, no need to even pg_dump a schema definition.
I also found it works fine with cockroachdb.
Re: How We Went All In on sqlc/pgx for Postgres and Go
#4It allows drop in replacement of SQLite that is in pure Go - no CGO or anything required for compilation, while still having everything implemented from SQLite.
Insert speed is a bit lacking (about ~6x slower in my experience compared to the CGO sqlite3 package), but its good enough for me.
Re: How We Went All In on sqlc/pgx for Postgres and Go
#5I like the approach of starting with the database schema and generating code to reflect that. I define my schema in sql files and handle database migrations using https://github.com/golang-migrate/migrate.
If you take this approach, you can mostly avoid exposing details about the SQL driver being used, and since the driver is mostly used by a few templates, swapping drivers doesn't take much effort.
Re: How We Went All In on sqlc/pgx for Postgres and Go
#6Re: How We Went All In on sqlc/pgx for Postgres and Go
#7As an aside - for anyone working with databases in Go, check out https://pkg.go.dev/modernc.org/sqlite It allows drop in replacement of SQLite that is in pure Go - no CGO or anything required for compilation, while still having everything implemented from SQLite. Insert speed is a bit lacking (about ~6x slower in my experience compared to the CGO sqlite3 package), but its good enough for me.
SQLite 2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0ff3f
0 errors out of 928271 tests on 3900x Linux 64-bit little-endian
Whee, I shall have to give it a go - thanks for the heads-up :-)Re: How We Went All In on sqlc/pgx for Postgres and Go
#8sqlc is a great code generator that seems to work miracles. It uses the official postgres parser to know all the types of your tables and queries, and can generate perfect Go structs from this. It even knows your table and field types just from reading your migrations, tracking changes perfectly, no need to even pg_dump a schema definition. I also found it works fine with cockroachdb.
I ask because I'm still trying to find a good solution for my project.
Re: How We Went All In on sqlc/pgx for Postgres and Go
#9sqlc is a great code generator that seems to work miracles. It uses the official postgres parser to know all the types of your tables and queries, and can generate perfect Go structs from this. It even knows your table and field types just from reading your migrations, tracking changes perfectly, no need to even pg_dump a schema definition. I also found it works fine with cockroachdb.
How are migrations defined? I ask because I'm still trying to find a good solution for my project.