A typed ORM for Go. Plain structs, compiler-checked queries, no code generation.
Documentation Β· Quick start Β· Choose your path Β· Examples Β· Blog
Columns are field pointers, not strings. Write ant.Gt(&Users.Age, 18) and the compiler checks both the column and the value. Rename a field and every query follows.
type User struct {
ant.Base // ID, CreatedAt, UpdatedAt
Name string
Age int
Posts []Post // 1:N through Post.UserID
}
type Post struct {
ant.Base
UserID int64
Title string
}
type AppDB struct {
ant.Context
Users ant.Table[User]
Posts ant.Table[Post]
}
var Users = ant.Fields[User]()
db, err := ant.Open[AppDB](ctx, postgres.Dialect, dsn) // shared: reads and inserts, no tracking
session := ant.Session(db) // one per request: it tracks what it loads, for SaveChanges
adults, err := session.Users.
Where(ant.Gt(&Users.Age, 18)). // ant.Gt(&Users.Age, "18") won't compile
Include(&Users.Posts). // one batched query, not one per user
All(ctx)
adults[0].Age++
err = session.SaveChanges(ctx) // writes only the columns that changedant-showcase.mp4
go get github.com/skudra-go/ant
go get github.com/jackc/pgx/v5/stdlib # or the driver for your databaseRequires Go 1.27 or later, for generic methods.
hello is one file on SQLite. It needs only Go:
go run github.com/skudra-go/ant-examples/examples/hello@latestCreated Alice
Alice is 30 and has 2 posts
Happy birthday, Alice
The first run takes about 30 seconds, mostly compiling the SQLite driver. To read or change the code, clone ant-examples and run go run . in examples/hello. The quick start walks through the same program.
The same query in each: users over 18 with their posts, sorted by name, 10 at a time. A test checks that all four return the same rows.
|
ant: checked, with nothing generated users, err := db.Users.
Include(&Users.Posts).
Where(ant.Gt(&Users.Age, 18)).
OrderBy(&Users.Name).
Limit(10).
All(ctx) |
GORM 1.31: strings, so a typo fails at run time var users []User
err := db.WithContext(ctx).
Preload("Posts").
Where("age > ?", 18).
Order("name").
Limit(10).
Find(&users).
Error |
|
Bun 1.3: strings, so a typo fails at run time var users []User
err := db.NewSelect().
Model(&users).
Relation("Posts").
Where("age > ?", 18).
Order("name").
Limit(10).
Scan(ctx) |
ent 0.14: checked, through generated code users, err := client.User.Query().
WithPosts().
Where(user.AgeGT(18)).
Order(user.ByName()).
Limit(10).
All(ctx) |
| Mistake | ant | GORM | Bun | ent | sqlc |
|---|---|---|---|---|---|
Misspelled column, agee |
β | β | β | β | |
"18" for an int |
β | β | β | β | β |
Misspelled relation, Psots |
β | β | β | β | |
| Column of another model | β | β | β | ||
| No code generation step | β | β | β | β | β |
β
compile error Β sqlc generate, or antvet for ant) Β β compiles, fails at run time Β β needs a generate step
Each cell was tested by compiling the mistake. GORM also has an optional CLI that generates typed field helpers.
tools/compare runs the same operations in each library against PostgreSQL 17 on one machine (Ryzen 5 3600, Docker on WSL2). Each number is the median of 10 runs, and each run repeats the operation hundreds to thousands of times. The database round trip is included, which is why small queries are close. Commits don't wait for the disk, so writes measure the library and not the drive. Plain SQL (a hand-written query and Scan, what sqlc generates) is the baseline. Lower is better; π’ is the best in each row, shared by any within 1%. Time per operation, in microseconds:
| Β΅s per operation | ant | ant NoTracking |
GORM | Bun | ent | Plain SQL baseline |
|
|---|---|---|---|---|---|---|---|
| Read 1000 rows | 2,075 | π’ 1,692 | 3,361 | 2,370 | 2,240 | 1,692 | |
| Find one by key | 442 | 397 | 405 | π’ 384 | 398 | 398 | |
| Filter, sort, 10 rows | 557 | π’ 539 | 568 | π’ 535 | 556 | 535 | |
| 100 users, 500 posts | 2,238 | π’ 1,774 | 2,731 | 2,030 | 2,031 | 1,581 | |
| Insert one | 410 | β | 420 | 1,112 | π’ 404 | 392 | |
| Update one column | π’ 399 | β | 407 | 424 | π’ 402 | 390 | |
| Load, edit, save | π’ 805 | β | 818 | π’ 812 | 1,869 | 798 |
What the numbers say:
- Small queries cost about the same in every library.
- Change tracking costs on large reads: 1000 rows take 1.2 times as long and twice the memory, because ant keeps a copy of each row to find changes. With
NoTracking, ant is level with plain SQL here. - With
NoTrackingwhere it applies, ant uses the least memory of the four libraries in every operation. Benchmarks has the memory and allocation tables. - Bun's insert is slow by default (it prepares every insert as a new statement), and ent's update reads the row back. tools/compare has the details.
- Queries the compiler checks: conditions, joins, projections, aggregates, subqueries, CTEs and window functions.
- Relations: one-to-one, one-to-many and many-to-many, loaded in batches with
Include. Nothing loads behind your back. - Change tracking: load, edit, call
SaveChanges, and only the changed columns are written. - Writes: whole graphs in one call,
Upsert,MERGE,COPYand bulk updates, and a guard against anUPDATEorDELETEwith no condition. - Transactions with savepoints, isolation levels, retries and read replicas.
- Lifecycle: soft deletes, timestamps, tenant filters, hooks, validation and optimistic concurrency.
- Migrations: plain SQL that
diffwrites from your structs anddriftchecks against the database, with no down migrations and no lock-in. - Tooling: N+1 warnings,
log/sloglogging, ago vetanalyzer, metrics, OpenTelemetry, and test helpers inanttest.
Four of the example projects are much bigger than a demo, and each README writes down what didn't fit.
- listmonk: part of the data layer of listmonk, a newsletter manager in Go, ported to ant on the schema its own installer creates. Each ported query is checked against listmonk's SQL on the same rows.
- pagila: ant adopted on the Pagila sample database. The models were written by hand and checked with
drift, thenadoptandbaselinestarted the history without touching the data. - azugo: a web service with a UUID key on every model from one embedded struct, validation errors returned as 422, and cursor paging over a nullable column.
- ledger: double-entry bookkeeping for several tenants, with transfers that are safe to retry, balances the database enforces, an outbox and encrypted fields.
| PostgreSQL | MySQL | MariaDB | SQLite | SQL Server | |
|---|---|---|---|---|---|
| Queries and writes | β | β | β | β | β |
| Migrations | β |
PostgreSQL gets every feature first. Databases lists what each one lacks and how ant handles the differences.
- Migrations are PostgreSQL only. On MySQL, MariaDB, SQLite and SQL Server, ant reads and writes, and you manage the schema with your own tool or plain SQL.
- The full test suite runs on PostgreSQL only. The other databases run a smaller one, so expect more rough edges there.
- ant is pre-1.0, so the API can still change. Each release lists its breaking changes.
The roadmap lists what's planned, and why some items were skipped.
- Documentation: guides, recipes and reference.
- Guides: migrating from GORM, ant vs GORM, ent, Bun and sqlc, type-safe SQL in Go, database migrations in Go, UUID primary keys and using an existing database.
- Feature examples: a short test for every feature, edge cases included.
- Example projects: from one file on SQLite to a port of a real application.
- Roadmap and design decisions.
ant is newer than most models' training data, so an assistant left to guess writes GORM. Give it the docs:
- Claude Code:
/plugin marketplace add skudra-go/ant, then/plugin install ant@ant. The skill loads whenever a task touches ant. - Codex, Cursor, Copilot, Gemini CLI and other agents:
npx skills add skudra-go/antinstalls the same skill. - Any assistant: point it at skudra.net/llms.txt, the docs as Markdown, or llms-full.txt, all of them in one file.
To have every assistant on a project pick it up, add a line to its AGENTS.md or CLAUDE.md:
This project uses the ant ORM (github.com/skudra-go/ant), not GORM. Before writing ant code, read https://skudra.net/llms.txt.Issues and pull requests are welcome. Read CONTRIBUTING.md first. Report vulnerabilities as SECURITY.md describes.
Thank you to everyone who has filed an issue, fixed a bug or improved the docs:
Skudra means ant in Latvian, which is where skudra.net gets its name :)
The feature list started from the catalogs of Entity Framework Core, Laravel's Eloquent and the Go libraries above, so Include and SaveChanges will look familiar to anyone who has used EF Core.