Entgo Skills for AI Agents
This skill provides comprehensive entgo entity framework knowledge, optimized for AI agents helping developers build production-ready Go applications with type-safe database operations.
🎯 When to Use This Skill
Invoke this skill when working with entgo:
- Schema design: Defining entities, fields, relationships, indexes
- CRUD operations: Creating type-safe database operations
- Query optimization: Eager loading, pagination, aggregation
- Access control: Privacy policies, multi-tenant filtering
- Business logic: Hooks, validation, default values
- Database migrations: Schema versioning with Atlas
- Troubleshooting: Fixing entgo issues, understanding errors
📚 Knowledge Structure
Load specific guides as needed rather than reading everything at once:
Quick Start
Link: Official Ent Documentation
Contains: Installation, creating schemas, code generation, database connection
Pattern Guides
Schema Definition
| File |
When to Load |
| references/schema-fields.md |
Field types, validation, constraints |
| references/schema-edges.md |
Relationships (O2O, O2M, M2M), through tables |
| references/schema-indexes.md |
Single, composite, unique indexes |
| references/schema-mixins.md |
Reusable field groups (timestamp, soft delete) |
| references/schema-annotations.md |
Code generation hints, GraphQL, gRPC |
CRUD Operations
| File |
When to Load |
| references/crud-create.md |
Create, CreateBulk, relations on create |
| references/crud-query.md |
Query, Where, predicates, sorting, pagination |
| references/crud-update.md |
UpdateOne, Update, upsert operations |
| references/crud-delete.md |
DeleteOne, Delete, soft delete patterns |
Advanced Queries
| File |
When to Load |
| references/query-predicates.md |
Where conditions, operators, custom SQL |
| references/query-eager-load.md |
WithX methods, nested loading, N+1 prevention |
| references/query-traversal.md |
Edge traversal, graph queries |
| references/query-aggregation.md |
Count, Sum, GroupBy, custom aggregates |
| references/query-pagination.md |
Offset/Limit, cursor pagination |
Business Logic
| File |
When to Load |
| references/hooks.md |
Schema hooks, global hooks, validation |
| references/privacy.md |
Policy rules, multi-tenant, RBAC |
| references/validation.md |
Field validation, mutation validation |
| references/transactions.md |
Tx, WithTx, context propagation |
Database & Migrations
| File |
When to Load |
| references/migrations-auto.md |
Schema.Create, auto migration |
| references/migrations-versioned.md |
Atlas, versioned migrations |
| references/database-config.md |
MySQL, PostgreSQL, SQLite, connection pool |
| references/postgresql-specific.md |
PostgreSQL arrays, enums, JSONB, FTS |
| references/codegen.md |
Generate command, features, templates |
| references/custom-templates.md |
External templates, extensions |
Integration & Extensions
| File |
When to Load |
| references/graphql-entgql.md |
GraphQL integration with gqlgen |
| references/grpc-entproto.md |
gRPC/Protobuf integration |
Advanced Features
| File |
When to Load |
| references/json-operations.md |
JSON field operations, predicates |
| references/locking.md |
Pessimistic/Optimistic locking |
| references/interceptors.md |
Query interceptors |
| references/views.md |
SQL views, materialized views |
Best Practices
| File |
When to Load |
| best-practices/project-structure.md |
Directory layout, naming conventions |
| best-practices/error-handling.md |
Error types, wrapping, checking |
| best-practices/soft-delete.md |
Soft delete implementation |
| best-practices/testing.md |
Testing with ent, fixtures |
Troubleshooting
| File |
When to Load |
| troubleshooting/common-errors.md |
Not found, constraint errors |
| troubleshooting/migration-issues.md |
Migration failures, schema drift |
| troubleshooting/performance.md |
N+1, query optimization |
🚀 Quick Examples
Basic Schema
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("name").NotEmpty(),
field.String("email").Unique(),
field.Int("age").Positive(),
}
}
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("pets", Pet.Type),
}
}
CRUD Operations
// Create
user, err := client.User.Create().
SetName("Alice").
SetEmail("alice@example.com").
Save(ctx)
// Query with eager loading
users, err := client.User.Query().
Where(user.AgeGT(18)).
WithPets().
All(ctx)
// Update
_, err := client.User.UpdateOneID(id).
SetName("Bob").
Save(ctx)
// Delete
err := client.User.DeleteOneID(id).Exec(ctx)
Transaction
err := WithTx(ctx, client, func(tx *ent.Tx) error {
u, err := tx.User.Create().SetName("Alice").Save(ctx)
if err != nil {
return err
}
_, err = tx.Pet.Create().SetName("Fluffy").SetOwner(u).Save(ctx)
return err
})
🔗 External Resources
1---2name: entgo-skills3description: Comprehensive knowledge base for entgo.io - Go's entity framework for building and maintaining applications with large data models. **Use this skill when:** - Defining database schemas with type-safe ORM - Building CRUD operations with complex relationships - Implementing database hooks and privacy policies - Managing database migrations with Atlas - Optimizing queries with eager loading and pagination - Setting up multi-tenant data access control **Features:** - Complete schema definition patterns (fields, edges, indexes, mixins) - Type-safe CRUD with generated code - Advanced query patterns (predicates, aggregation, traversal) - Production patterns (hooks, privacy, soft delete) - Migration strategies (auto and versioned)4license: MIT5---67# Entgo Skills for AI Agents89This skill provides comprehensive entgo entity framework knowledge, optimized for AI agents helping developers build production-ready Go applications with type-safe database operations.1011## 🎯 When to Use This Skill1213Invoke this skill when working with entgo:14- **Schema design**: Defining entities, fields, relationships, indexes15- **CRUD operations**: Creating type-safe database operations16- **Query optimization**: Eager loading, pagination, aggregation17- **Access control**: Privacy policies, multi-tenant filtering18- **Business logic**: Hooks, validation, default values19- **Database migrations**: Schema versioning with Atlas20- **Troubleshooting**: Fixing entgo issues, understanding errors2122## 📚 Knowledge Structure2324**Load specific guides as needed** rather than reading everything at once:2526### Quick Start27**Link**: [Official Ent Documentation](https://entgo.io/docs/getting-started)28**Contains**: Installation, creating schemas, code generation, database connection2930### Pattern Guides3132#### Schema Definition33| File | When to Load |34|------|-------------|35| [references/schema-fields.md](references/schema-fields.md) | Field types, validation, constraints |36| [references/schema-edges.md](references/schema-edges.md) | Relationships (O2O, O2M, M2M), through tables |37| [references/schema-indexes.md](references/schema-indexes.md) | Single, composite, unique indexes |38| [references/schema-mixins.md](references/schema-mixins.md) | Reusable field groups (timestamp, soft delete) |39| [references/schema-annotations.md](references/schema-annotations.md) | Code generation hints, GraphQL, gRPC |4041#### CRUD Operations42| File | When to Load |43|------|-------------|44| [references/crud-create.md](references/crud-create.md) | Create, CreateBulk, relations on create |45| [references/crud-query.md](references/crud-query.md) | Query, Where, predicates, sorting, pagination |46| [references/crud-update.md](references/crud-update.md) | UpdateOne, Update, upsert operations |47| [references/crud-delete.md](references/crud-delete.md) | DeleteOne, Delete, soft delete patterns |4849#### Advanced Queries50| File | When to Load |51|------|-------------|52| [references/query-predicates.md](references/query-predicates.md) | Where conditions, operators, custom SQL |53| [references/query-eager-load.md](references/query-eager-load.md) | WithX methods, nested loading, N+1 prevention |54| [references/query-traversal.md](references/query-traversal.md) | Edge traversal, graph queries |55| [references/query-aggregation.md](references/query-aggregation.md) | Count, Sum, GroupBy, custom aggregates |56| [references/query-pagination.md](references/query-pagination.md) | Offset/Limit, cursor pagination |5758#### Business Logic59| File | When to Load |60|------|-------------|61| [references/hooks.md](references/hooks.md) | Schema hooks, global hooks, validation |62| [references/privacy.md](references/privacy.md) | Policy rules, multi-tenant, RBAC |63| [references/validation.md](references/validation.md) | Field validation, mutation validation |64| [references/transactions.md](references/transactions.md) | Tx, WithTx, context propagation |6566#### Database & Migrations67| File | When to Load |68|------|-------------|69| [references/migrations-auto.md](references/migrations-auto.md) | Schema.Create, auto migration |70| [references/migrations-versioned.md](references/migrations-versioned.md) | Atlas, versioned migrations |71| [references/database-config.md](references/database-config.md) | MySQL, PostgreSQL, SQLite, connection pool |72| [references/postgresql-specific.md](references/postgresql-specific.md) | PostgreSQL arrays, enums, JSONB, FTS |73| [references/codegen.md](references/codegen.md) | Generate command, features, templates |74| [references/custom-templates.md](references/custom-templates.md) | External templates, extensions |7576#### Integration & Extensions77| File | When to Load |78|------|-------------|79| [references/graphql-entgql.md](references/graphql-entgql.md) | GraphQL integration with gqlgen |80| [references/grpc-entproto.md](references/grpc-entproto.md) | gRPC/Protobuf integration |8182#### Advanced Features83| File | When to Load |84|------|-------------|85| [references/json-operations.md](references/json-operations.md) | JSON field operations, predicates |86| [references/locking.md](references/locking.md) | Pessimistic/Optimistic locking |87| [references/interceptors.md](references/interceptors.md) | Query interceptors |88| [references/views.md](references/views.md) | SQL views, materialized views |8990### Best Practices91| File | When to Load |92|------|-------------|93| [best-practices/project-structure.md](best-practices/project-structure.md) | Directory layout, naming conventions |94| [best-practices/error-handling.md](best-practices/error-handling.md) | Error types, wrapping, checking |95| [best-practices/soft-delete.md](best-practices/soft-delete.md) | Soft delete implementation |96| [best-practices/testing.md](best-practices/testing.md) | Testing with ent, fixtures |9798### Troubleshooting99| File | When to Load |100|------|-------------|101| [troubleshooting/common-errors.md](troubleshooting/common-errors.md) | Not found, constraint errors |102| [troubleshooting/migration-issues.md](troubleshooting/migration-issues.md) | Migration failures, schema drift |103| [troubleshooting/performance.md](troubleshooting/performance.md) | N+1, query optimization |104105## 🚀 Quick Examples106107### Basic Schema108```go109func (User) Fields() []ent.Field {110 return []ent.Field{111 field.String("name").NotEmpty(),112 field.String("email").Unique(),113 field.Int("age").Positive(),114 }115}116117func (User) Edges() []ent.Edge {118 return []ent.Edge{119 edge.To("pets", Pet.Type),120 }121}122```123124### CRUD Operations125```go126// Create127user, err := client.User.Create().128 SetName("Alice").129 SetEmail("alice@example.com").130 Save(ctx)131132// Query with eager loading133users, err := client.User.Query().134 Where(user.AgeGT(18)).135 WithPets().136 All(ctx)137138// Update139_, err := client.User.UpdateOneID(id).140 SetName("Bob").141 Save(ctx)142143// Delete144err := client.User.DeleteOneID(id).Exec(ctx)145```146147### Transaction148```go149err := WithTx(ctx, client, func(tx *ent.Tx) error {150 u, err := tx.User.Create().SetName("Alice").Save(ctx)151 if err != nil {152 return err153 }154 _, err = tx.Pet.Create().SetName("Fluffy").SetOwner(u).Save(ctx)155 return err156})157```158159## 🔗 External Resources160161- **Official Docs**: https://entgo.io/docs162- **GitHub**: https://github.com/ent/ent163- **Atlas Migration**: https://atlasgo.io164- **Examples**: https://github.com/ent/ent/tree/master/examples