尚未收集仓库信息。
尚未检测到更新。GitHub 发布版本后会显示在这里。
🐜 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
翻译准备中
正在加载完整 README。
查看完整 README ↗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
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.
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.
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 ⚠️ 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.
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.
| µs per operation | ant | antNoTracking | GORM | Bun | ent | Plain SQLbaseline | |
|---|---|---|---|---|---|---|---|
| Read 1000 rows | 2,799 | 🟢 1,688 | 3,285 | 2,259 | 2,226 | 1,557 | |
| Find one by key | 406 | 389 | 416 | 🟢 372 | 383 | 365 | |
| Filter, sort, 10 rows | 574 | 🟢 552 | 561 | 584 | 635 | 518 | |
| 100 users, 500 posts | 3,039 | 🟢 2,091 | 3,034 | 2,198 | 2,194 | 1,750 | |
| Insert one | 🟢 431 | – | 442 | 1,164 | 441 | 400 | |
| Update one column | 🟢 413 | – | 444 | 444 | 🟢 412 | 396 | |
| Load, edit, save | 830 | – | 861 | 🟢 779 | 1,784 | 806 |
| KiB per operation | ant | antNoTracking | GORM | Bun | ent | Plain SQLbaseline | |
|---|---|---|---|---|---|---|---|
| Read 1000 rows | 823 | 🟢 277 | 392 | 295 | 589 | 257 | |
| Find one by key | 7.5 | 6.5 | 5.7 | 6.3 | 🟢 4.9 | 1.5 | |
| Filter, sort, 10 rows | 15.1 | 10.5 | 9.7 | 🟢 9.3 | 11.9 | 3.8 | |
| 100 users, 500 posts | 649 | 327 | 362 | 🟢 277 | 335 | 257 | |
| Insert one | 4.3 | – | 7.0 | 6.8 | 🟢 3.7 | 1.3 | |
| Update one column | 🟢 2.9 | – | 5.6 | 5.0 | 3.1 | 0.3 | |
| Load, edit, save | 🟢 10.2 | – | 11.2 | 11.2 | 10.7 | 1.8 |
What the numbers say:
NoTracking, ant is the fastest here.以上为 README 的开头部分。其余内容请阅读原文。 查看完整 README ↗