all: replace save with exec when the model is not needed

This commit is contained in:
Ariel Mashraki
2021-09-01 22:07:48 +03:00
committed by Ariel Mashraki
parent 7015647528
commit f0d985f542
8 changed files with 51 additions and 54 deletions

View File

@@ -158,7 +158,7 @@ func QueryCarUsers(ctx context.Context, a8m *ent.User) error {
}
func CreateGraph(ctx context.Context, client *ent.Client) error {
// first, create the users.
// First, create the users.
a8m, err := client.User.
Create().
SetAge(30).
@@ -175,48 +175,48 @@ func CreateGraph(ctx context.Context, client *ent.Client) error {
if err != nil {
return err
}
// then, create the cars, and attach them to the users in the creation.
_, err = client.Car.
// Then, create the cars, and attach them to the users in the creation.
err = client.Car.
Create().
SetModel("Tesla").
SetRegisteredAt(time.Now()). // ignore the time in the graph.
SetOwner(a8m). // attach this graph to Ariel.
Save(ctx)
Exec(ctx)
if err != nil {
return err
}
_, err = client.Car.
err = client.Car.
Create().
SetModel("Mazda").
SetRegisteredAt(time.Now()). // ignore the time in the graph.
SetOwner(a8m). // attach this graph to Ariel.
Save(ctx)
Exec(ctx)
if err != nil {
return err
}
_, err = client.Car.
err = client.Car.
Create().
SetModel("Ford").
SetRegisteredAt(time.Now()). // ignore the time in the graph.
SetOwner(neta). // attach this graph to Neta.
Save(ctx)
Exec(ctx)
if err != nil {
return err
}
// create the groups, and add their users in the creation.
_, err = client.Group.
// Create the groups, and add their users in the creation.
err = client.Group.
Create().
SetName("GitLab").
AddUsers(neta, a8m).
Save(ctx)
Exec(ctx)
if err != nil {
return err
}
_, err = client.Group.
err = client.Group.
Create().
SetName("GitHub").
AddUsers(a8m).
Save(ctx)
Exec(ctx)
if err != nil {
return err
}