Skip to content
Projects

skudra-go/ant has 42 GitHub stars and 6 forks. GitHot measured +6 stars in 24 hours. Last checked 2026-11-17 04:57 UTC. Last push 2026-11-14.

How these counts are measured

42 stars6 Forks +6 in 24h

What you can do

  • Typed queries: conditions, joins, projections, aggregates, subqueries, CTEs and window functions, all checked by the compiler
  • Plain structs: your types are the models, with conventions you can override in Configure
  • Relations: 1:1, 1:N and many-to-many, loaded explicitly with Include, in batches. Nothing loads behind your back
  • Change tracking: load, edit, SaveChanges. Only the columns that changed are written

Measured star growth

in 24h
+6
in 7 days
Collecting history
in 15 days
Collecting history
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

About

🐜 ant is a Golang ORM, that leverages modern generics to enable strict typing and incredible developer experience. Inspired by ASP.NET's Entity Framework and Laravel

Data

README.md

Original

ant

A typed ORM for Go. Plain structs, compiler-checked queries, no code generation.

Documentation · Quick start · Examples

CI Go Reference Go 1.27+ MIT license


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)

adults, err := db.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 = db.SaveChanges(ctx) // writes only the columns that changed

See it

https://github.com/user-attachments/assets/718a63de-dfe2-4749-a923-51e79dd53a2a

Install

go get github.com/skudra-go/ant
go get github.com/jackc/pgx/v5/stdlib  # or the driver for your database

Requires Go 1.27 or later, for generic methods.

Try it in a minute

examples/hello is one file on SQLite. It needs only Go:

git clone https://github.com/skudra-go/ant-examples
cd ant-examples/examples/hello
go run .
Created Alice
Alice is 30 and has 2 posts
Happy birthday, Alice

The first run takes about 30 seconds, mostly compiling the SQLite driver. The quick start walks through the same program.

Next to GORM, Bun and ent

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)

What the compiler catches

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   ⚠️ caught by a separate step (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.

Performance

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%.

µ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
KiB per operation ant ant
NoTracking
GORM Bun ent Plain SQL
baseline
Read 1000 rows 582 🟢 275 392 295 589 257
Find one by key 3.8 🟢 3.5 5.7 6.3 4.9 1.5
Filter, sort, 10 rows 11.5 🟢 7.9 9.7 9.2 11.9 3.8
100 users, 500 posts 486 🟢 241 362 277 335 257
Insert one 🟢 2.5 – 7.0 6.8 3.7 1.3
Update one column 🟢 2.5 – 5.6 5.0 3.1 0.3
Load, edit, save 🟢 5.8 – 11.2 11.2 10.7 1.8

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.
  • ant uses the least memory of the four libraries in every row.
  • 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.

Features

  • Typed queries: conditions, joins, projections, aggregates, subqueries, CTEs and window functions, all checked by the compiler
  • Plain structs: your types are the models, with conventions you can override in Configure
  • Relations: 1:1, 1:N and many-to-many, loaded explicitly with Include, in batches. Nothing loads behind your back
  • Change tracking: load, edit, SaveChanges. Only the columns that changed are written
  • Writes: insert, update, delete, upserts, MERGE and bulk writes, with a guard against unfiltered updates and deletes
  • Transactions: savepoints, isolation levels, retries and read replicas
  • Lifecycle: soft deletes, timestamps, global filters, hooks, validation and optimistic concurrency
  • Migrations: plain SQL generated from your structs, with drift checks. No down migrations, and no lock-in
  • Tooling: a go vet analyzer, query logging, metrics, OpenTelemetry, and test fixtures and factories in anttest

Databases

PostgreSQL MySQL MariaDB SQLite SQL Server
Queries and writes ✅ ✅ ✅ ✅ ✅
Migrations ✅

PostgreSQL gets every feature first. docs/databases.md lists what each database lacks.

What's missing

  • 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.

Learn more

With an AI assistant

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/ant installs 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.

Contributing

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:

About

Skudra means ant in Latvian, which is where skudra.net gets its name :)

License

MIT