As mentioned in the introduction section, running
ent on the schemas, will generate the following assets:
Txobjects used for interacting with the graph.
- CRUD builders for each schema type. See CRUD for more info.
- Entity object (Go struct) for each of the schema type.
- Package containing constants and predicates used for interacting with the builders.
migratepackage for SQL dialects. See Migration for more info.
Gremlin (AWS Neptune)
Save a user.
SaveX a pet; Unlike Save, SaveX panics if an error occurs.
Save a bulk of pets.
Update an entity that was returned from the database.
Filter using predicates.
In PostgreSQL, the conflict target is required:
In order to customize the executed statement, use the SQL API:
Since the upsert API is implemented using the
ON CONFLICT clause (and
ON DUPLICATE KEY in MySQL), Ent executes only one statement to the database, and therefore, only create hooks are applied for such operations. :::
Get all users with followers.
Get all followers of a specific user; Start the traversal from a node in the graph.
Get all pets of the followers of a user.
Count the number of posts without comments.
More advance traversals can be found in the next section.
Get all pet names.
Get all unique pet names.
Count the number of unique pet names.
Select partial objects and partial associations.gs Get all pets and their owners, but select and fill only the
Scan all pet names and ages to custom struct.
Update an entity and return a partial of it.
Delete an entity.
Delete by ID.
Delete using predicates.
Each generated node type has its own type of mutation. For example, all
User builders, share the same generated
UserMutation object. However, all builder types implement the generic
For example, in order to write a generic code that apply a set of methods on both
ent.UserUpdate, use the
In some cases, you want to apply a set of methods on multiple types. For cases like this, either use the generic
ent.Mutation interface, or create your own interface.