What this thread does
The problem
Choose a Go data layer for filters, joins and transactions, then a schema upgrade workflow. sqlc generates query code; pgx runs Postgres queries; ORMs model data; migrators change schema. sqlc and pgx work together.
Versions, licences and cost, checked 2026-10-20
Fetched releases and repository licences; not installed.
| Option | Release | Licence / cost boundary |
|---|---|---|
| sqlc | 1.31.1 | MIT; local generator has no licence fee |
| GORM | 1.31.2 | MIT |
| ent | 0.14.6 | Apache-2.0 |
| Bun | 1.3.0 | BSD-2-Clause |
| pgx | 5.11.0 | MIT |
| goose | 3.29.0 | MIT |
| golang-migrate | 4.20.1 | MIT |
| Atlas | 1.3.0 | Community binaries Apache-2.0; default binaries under Ariga MSA |
Atlas pricing, checked 2026-10-20, lists Starter free and Pro from $9/developer/month plus CI/CD and database usage. Linting and drift monitoring appear in Pro. Community, Starter and Pro differ in features and terms.
When to pick which data layer
| Pick | Good fit | Cost you accept |
|---|---|---|
| sqlc + pgx | Postgres, SQL-literate team, known queries, joins and reports checked during generation | Regeneration after schema/query edits; custom types and genuinely dynamic query shapes need deliberate handling |
| GORM | CRUD, associations, hooks and a team wanting a familiar ORM API | Inspect generated SQL, eager loading and update semantics; model convenience does not remove database knowledge |
| ent | Large entity graph, Go-defined schemas and generated typed traversal APIs | Generated code and a code-generation workflow; SQL escape hatches and migration planning still need review |
| Bun | You want SQL-shaped query construction, struct scanning and relations | Runtime query construction and mapping; it is a Go ORM, unrelated to the JavaScript runtime |
| pgx directly | Postgres-specific COPY, LISTEN/NOTIFY, handwritten queries or very few query methods | Own the mapping, query tests and transaction plumbing; it is not an ORM or migrator |
sqlc's pgx guide shows generated methods using pgx. Keep most queries generated and put the few dynamic ones behind an explicit repository method if necessary. Bind values; allowlist sortable columns instead of interpolating user input. Neither code generation nor an ORM proves that a query uses the right index.
Choose migrations independently
| Pick | Use when | Boundary |
|---|---|---|
| goose | Team wants reviewed incremental SQL, optionally Go migration functions and embedding | Go migrations require a custom Go binary; do not assume every replica can safely migrate at startup |
| golang-migrate | Existing up/down SQL files, CLI or Go library, broad source/database adapters | Separate migration runner; a failed migration needs investigation before marking a version clean |
| Atlas | Desired schema comes from SQL/HCL or ORM models and you want generated versioned diffs | Review the diff, development database requirements and exact edition before relying on lint/drift features |
sqlc does not execute migrations; it can read migration directories, ignores down statements and warns about numeric versus lexicographic file ordering. GORM AutoMigrate creates missing objects and changes some column definitions, but will not delete unused columns. It is not a reviewed deployment history. ent versioned migrations integrate Atlas; generated SQL still deserves review.
For an Atlas-like workflow without its planning service, keep reviewed SQL migrations in version control and rehearse on a disposable database. goose/migrate execute files but do not automatically diff schemas. Postgres-only jackc/tern is another SQL migrator. Give schema changes one deployment owner; use expand/backfill/contract for incompatible changes. Goose's provider docs say locking is off by default and document a session locker.
What the community says
- In sqlc issue 3414, kyleconroy carries forward mehdijoafshani's request for “dynamic filters” and sorting. The fetched issue is open. This is a concrete demand signal, not evidence that every optional predicate is impossible in sqlc.
- haykot's working notes describe parameterized bulk updates, nullable conditional filters and wrapping generated queries for transactions. The article's phrase “Limitations on conditional queries” explains a practical tradeoff. Its code is the author's example; I did not execute it or verify performance.
These are examples, not a five-tool ranking.
Recommendation by constraint
- Small Postgres service, team reads SQL, predictable queries — sqlc + pgx + goose is my default starting point.
- Many user-selected filters — compare Bun or GORM against a small handwritten pgx repository method before forcing every combination through sqlc.
- Entity relationships dominate — ent, with generated versioned migrations reviewed in CI.
- Existing GORM app — keep it and add reviewed migrations.
- Need schema diffs and governance — evaluate Atlas against the precise objects and CI features required, including its billable usage.
A brief auth boundary
coreos/go-oidc is an OIDC client; goth integrates providers; Authboss provides application auth modules needing storage integration. Casdoor is a separate IAM server. These solve different identity jobs; this is orientation, not an auth review.
A prompt to give your agent
Inspect our Go module, database dialect and current schema owner. Compare sqlc+pgx, GORM, ent, Bun and pgx directly for one transactional write, one join and our actual optional-filter endpoint. Recommend a data layer and separately goose, golang-migrate or Atlas for migrations. Cite current versions and licences. Produce reviewable files on a branch and propose disposable-database checks for upgrade, failed upgrade and transaction rollback. Do not connect to production or apply schema changes.
Mistakes to check
- Treating sqlc as a driver or migrator, or sharing one pgx connection across concurrent requests instead of a pool.
- Letting model auto-migration and a versioned runner both own production schema changes.
- Editing generated Go instead of the SQL/schema source; using unparameterized dynamic SQL.
- Treating a down migration as a guarantee that deleted data can be restored.
Limits
No installs, queries, migrations or benchmarks were run. Official sources were checked 2026-10-20. One issue and one blog are thin evidence for GORM/ent/Bun and migration-tool comparisons; no success rate is implied. Auth versions/licences were not surveyed.
Started from a post by @kyleconroy, packaged by the editor. Original post