Skip to main content

ant vs GORM, ent, Bun and sqlc

All five are solid ways to talk to a SQL database from Go. They differ in when a mistake shows up, what you have to keep in step, and what the library does for you after a row is loaded. This page sums that up and says when each one fits, ant included. Why ant has the longer, side-by-side version.

At a glance​

antGORMBunentsqlc
You writeGo structsGo structsGo structsA schema in ent's Go DSLSQL
Columns in queriesField pointersStringsStringsGenerated methodsYour SQL
Code generationNoneNone, or an optional CLINonego generatesqlc generate
Saving changesChanged columns, found by trackingSave writes every columnUpdate on a model writes every column unless you name themSetters on an update builderOne statement per shape of update
MigrationsSQL files from a diff of your structs, PostgreSQL onlyAutoMigrate, or Atlas for versioned filesIts own runner for Go and SQL migrationsAutomatic, or Atlas for versioned SQL filesNone: it reads your migration tool's files

What the compiler catches​

The same mistakes, made in each library's version of one query:

MistakeantGORMBunentsqlc
Misspelled columnCompile error: your editor and go build flag itNot caught: it compiles and fails at runtimeNot caught: it compiles and fails at runtimeCompile error: your editor and go build flag itCaught by sqlc generate, before the build
"18" for an intCompile error: your editor and go build flag itNot caught: it compiles and fails at runtimeNot caught: it compiles and fails at runtimeCompile error: your editor and go build flag itCompile error: your editor and go build flag it
Misspelled relationCompile error: your editor and go build flag itNot caught: it compiles and fails at runtimeNot caught: it compiles and fails at runtimeCompile error: your editor and go build flag itCaught by sqlc generate, before the build
Column of another modelCaught by antvet. ant refuses it before sending the queryNot caught: it compiles and fails at runtimeNot caught: it compiles and fails at runtimeCompile error: your editor and go build flag itCaught by sqlc generate, before the build
No code generation stepNothing to generateNothing to generateNothing to generateNeeds go generate after a schema changeNeeds sqlc generate after a query or schema change

Compile error, shown in your editor Caught by a separate step: sqlc generate, or antvet for ant Compiles and fails at runtime Needs go generate or sqlc generate

Each cell was tested by compiling the mistake, or for sqlc by running sqlc generate 1.30. GORM's optional CLI generates typed field helpers.

Speed​

tools/compare runs the same operations in each library against PostgreSQL 17. Plain database/sql stands in for sqlc, whose generated code is a query string and a Scan.

  • Single-row reads and writes cost about the same in every library, because the round trip to the database is most of the time.
  • On a 1000-row read, ant's change tracking makes it 1.2 times slower than with NoTracking, and uses twice the memory. With NoTracking, ant read the rows as fast as plain SQL in our runs.
  • ant used the least memory of the four libraries in every row. Bun made the fewest allocations on single-row reads and updates.
  • Bun's insert is slower by default, and ent's load, edit and save sends four statements instead of two. Benchmarks explains both.

Benchmarks has the full tables and how to run them yourself.

When to pick each​

GORM​

The most widely used Go ORM, with the most answers online, plugins, and drivers for databases beyond these five. Pick it when your team already knows it, when you need a database ant doesn't support, or when you can't move to Go 1.27. Its generics API and optional CLI add some of the checks the others have.

Bun​

A query builder that stays close to SQL, and among the fastest on small queries in our benchmarks. Pick it when you want SQL's shape in Go and are fine with column names as strings, caught by tests rather than the compiler.

ent​

Schemas as Go code, generated query methods, and the strongest compile-time checks of the five: it also catches a column from the wrong model, which ant leaves to antvet. Pick it when your data is graph-shaped, or when you want those checks and don't mind running go generate after every schema change.

sqlc​

You write SQL, and sqlc generates typed Go functions for it, as fast as hand-written code. Pick it when your team thinks in SQL and doesn't want relations loaded for it or changes tracked. A new shape of update needs a new statement.

ant​

Queries the compiler checks without generated code, change tracking that writes only the columns that changed, relations loaded in batches, and migrations that are plain SQL. Pick it when you want ent's checks on plain structs, or GORM's convenience without strings.

When ant is the wrong choice​

  • You can't use Go 1.27. ant needs generic methods.
  • You need a stable API today. ant is pre-1.0, and a release can still break the API. Each release lists what it broke.
  • You want migrations on MySQL, MariaDB, SQLite or SQL Server. ant's migrations are PostgreSQL only. It reads and writes the other four, but their schema stays with your current tool.
  • Your database isn't one of the five. ant supports PostgreSQL, MySQL, MariaDB, SQLite and SQL Server.
  • You want SQL to be the source of truth. sqlc fits that better.
  • You need the ecosystem. GORM has years of plugins, answers and people who know it. ant is new.
  • Some mistakes still compile. A field pointer from another model's probe compiles, and fails when the query runs or in go vet with antvet. ent and sqlc catch it earlier.

Next​