ent
Entity framework for Go that generates type-safe ORM code and graph traversals from schema definitions.
Official Documentation ↗ent v0.13+ / Go 1.20+. Check the official docs for the latest API surface.Installation
go get entgo.io/entMethods
No methods match this filter.
Overview
ent generates an ORM from Go schema definitions. It produces typed builders for creating, querying and traversing entities, along with hooks, policies and migration support.
Core Methods
Define schemas, run generation, then use client methods to create and query. Predicates express conditions, With methods eager-load edges, and schema migration creates or updates tables.
Usage Notes
Keep schemas in version control, use eager loading to avoid N+1 queries, and generate versioned migrations for production rather than relying on auto-migration.
Common Pitfalls
Regeneration is required after schema edits, and stale generated code causes compile errors. Missing eager loading causes hidden extra queries. Auto-migration on a live database can be risky without review.
Errors
The official API reference declares the following error types:
ent.NotFoundError(操作不满足条件时返回 “ent.NotFoundError”) — official text: “the operation will return an “ent.NotFoundError”.” (source: https://entgo.io/docs/crud, fetched 2026-11-08T17:50:30.000Z)
API reference evidence
Fetched from official sources on 2026-11-08T17:50:30.000Z via WebFetch https://entgo.io/docs/crud.
client.User.Create→ signature from https://entgo.io/docs/crud; official text: “a8m, err := client.User. // UserClient. Create(). // User create builder. SetName(“a8m”). // Set field value. SetNillableAge(age). // Avoid nil checks. AddGroups(g1, g2). // Add many edges. SetSpouse(nati). // Set unique”client.User.Query→ signature from https://entgo.io/docs/crud; official text: “users, err := client.User. // UserClient. Query(). // User query builder. Where(user.HasFollowers()). // filter only users with followers. All(ctx) // query and return.”
FAQ
- How does ent compare to gorm?
- ent is schema-first and generates strongly typed code with graph traversal support, while gorm is more dynamic and convention driven. ent trades some flexibility for compile-time safety.
- How do I run migrations?
- ent can auto-migrate in development with client.Schema.Create, and versioned migrations can be generated for production control.
- What is eager loading?
- WithPosts and similar methods load relationships in fewer round trips. Without eager loading, traversing edges later issues additional queries.
Report a problem with this API docOpens a pre-filled issue on GitHub.