entc/gen: use a set when tracking cleared fields in mutation template

Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
Alex Snast
2020-03-17 11:34:13 +02:00
parent 81a2f60e47
commit 25fdb52a03
220 changed files with 1109 additions and 964 deletions

View File

@@ -66,8 +66,8 @@ func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) {
node, err = gc.sqlSave(ctx)
return node, err
})
for i := len(gc.hooks); i > 0; i-- {
mut = gc.hooks[i-1](mut)
for i := len(gc.hooks) - 1; i >= 0; i-- {
mut = gc.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, gc.mutation); err != nil {
return nil, err

View File

@@ -49,8 +49,8 @@ func (gd *GroupDelete) Exec(ctx context.Context) (int, error) {
affected, err = gd.sqlExec(ctx)
return affected, err
})
for i := len(gd.hooks); i > 0; i-- {
mut = gd.hooks[i-1](mut)
for i := len(gd.hooks) - 1; i >= 0; i-- {
mut = gd.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, gd.mutation); err != nil {
return 0, err

View File

@@ -87,8 +87,8 @@ func (gu *GroupUpdate) Save(ctx context.Context) (int, error) {
affected, err = gu.sqlSave(ctx)
return affected, err
})
for i := len(gu.hooks); i > 0; i-- {
mut = gu.hooks[i-1](mut)
for i := len(gu.hooks) - 1; i >= 0; i-- {
mut = gu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, gu.mutation); err != nil {
return 0, err
@@ -255,8 +255,8 @@ func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
node, err = guo.sqlSave(ctx)
return node, err
})
for i := len(guo.hooks); i > 0; i-- {
mut = guo.hooks[i-1](mut)
for i := len(guo.hooks) - 1; i >= 0; i-- {
mut = guo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, guo.mutation); err != nil {
return nil, err

View File

@@ -36,7 +36,7 @@ type GroupMutation struct {
typ string
id *int
name *string
clearedFields map[string]bool
clearedFields map[string]struct{}
users map[int]struct{}
removedusers map[int]struct{}
}
@@ -49,7 +49,7 @@ func newGroupMutation(c config, op Op) *GroupMutation {
config: c,
op: op,
typ: TypeGroup,
clearedFields: make(map[string]bool),
clearedFields: make(map[string]struct{}),
}
}
@@ -221,7 +221,8 @@ func (m *GroupMutation) ClearedFields() []string {
// FieldCleared returns a boolean indicates if this field was
// cleared in this mutation.
func (m *GroupMutation) FieldCleared(name string) bool {
return m.clearedFields[name]
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value for the given name. It returns an
@@ -335,7 +336,7 @@ type UserMutation struct {
age *int
addage *int
name *string
clearedFields map[string]bool
clearedFields map[string]struct{}
groups map[int]struct{}
removedgroups map[int]struct{}
}
@@ -348,7 +349,7 @@ func newUserMutation(c config, op Op) *UserMutation {
config: c,
op: op,
typ: TypeUser,
clearedFields: make(map[string]bool),
clearedFields: make(map[string]struct{}),
}
}
@@ -586,7 +587,8 @@ func (m *UserMutation) ClearedFields() []string {
// FieldCleared returns a boolean indicates if this field was
// cleared in this mutation.
func (m *UserMutation) FieldCleared(name string) bool {
return m.clearedFields[name]
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value for the given name. It returns an

View File

@@ -75,8 +75,8 @@ func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
node, err = uc.sqlSave(ctx)
return node, err
})
for i := len(uc.hooks); i > 0; i-- {
mut = uc.hooks[i-1](mut)
for i := len(uc.hooks) - 1; i >= 0; i-- {
mut = uc.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, uc.mutation); err != nil {
return nil, err

View File

@@ -49,8 +49,8 @@ func (ud *UserDelete) Exec(ctx context.Context) (int, error) {
affected, err = ud.sqlExec(ctx)
return affected, err
})
for i := len(ud.hooks); i > 0; i-- {
mut = ud.hooks[i-1](mut)
for i := len(ud.hooks) - 1; i >= 0; i-- {
mut = ud.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, ud.mutation); err != nil {
return 0, err

View File

@@ -100,8 +100,8 @@ func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
affected, err = uu.sqlSave(ctx)
return affected, err
})
for i := len(uu.hooks); i > 0; i-- {
mut = uu.hooks[i-1](mut)
for i := len(uu.hooks) - 1; i >= 0; i-- {
mut = uu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, uu.mutation); err != nil {
return 0, err
@@ -295,8 +295,8 @@ func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
node, err = uuo.sqlSave(ctx)
return node, err
})
for i := len(uuo.hooks); i > 0; i-- {
mut = uuo.hooks[i-1](mut)
for i := len(uuo.hooks) - 1; i >= 0; i-- {
mut = uuo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, uuo.mutation); err != nil {
return nil, err