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

@@ -36,7 +36,7 @@ type PetMutation struct {
typ string
id *int
name *string
clearedFields map[string]bool
clearedFields map[string]struct{}
owner *int
clearedowner bool
}
@@ -49,7 +49,7 @@ func newPetMutation(c config, op Op) *PetMutation {
config: c,
op: op,
typ: TypePet,
clearedFields: make(map[string]bool),
clearedFields: make(map[string]struct{}),
}
}
@@ -218,7 +218,8 @@ func (m *PetMutation) ClearedFields() []string {
// FieldCleared returns a boolean indicates if this field was
// cleared in this mutation.
func (m *PetMutation) 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
@@ -329,7 +330,7 @@ type UserMutation struct {
age *int
addage *int
name *string
clearedFields map[string]bool
clearedFields map[string]struct{}
pets map[int]struct{}
removedpets map[int]struct{}
}
@@ -342,7 +343,7 @@ func newUserMutation(c config, op Op) *UserMutation {
config: c,
op: op,
typ: TypeUser,
clearedFields: make(map[string]bool),
clearedFields: make(map[string]struct{}),
}
}
@@ -580,7 +581,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

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

View File

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

View File

@@ -82,8 +82,8 @@ func (pu *PetUpdate) Save(ctx context.Context) (int, error) {
affected, err = pu.sqlSave(ctx)
return affected, err
})
for i := len(pu.hooks); i > 0; i-- {
mut = pu.hooks[i-1](mut)
for i := len(pu.hooks) - 1; i >= 0; i-- {
mut = pu.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, pu.mutation); err != nil {
return 0, err
@@ -242,8 +242,8 @@ func (puo *PetUpdateOne) Save(ctx context.Context) (*Pet, error) {
node, err = puo.sqlSave(ctx)
return node, err
})
for i := len(puo.hooks); i > 0; i-- {
mut = puo.hooks[i-1](mut)
for i := len(puo.hooks) - 1; i >= 0; i-- {
mut = puo.hooks[i](mut)
}
if _, err := mut.Mutate(ctx, puo.mutation); err != nil {
return nil, err

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