entc/gen: move predicates to mutation object (#825)

This commit is contained in:
Ariel Mashraki
2020-10-07 14:22:14 +03:00
committed by GitHub
parent 4cedff2d5f
commit c2cdc52946
171 changed files with 674 additions and 720 deletions

View File

@@ -12,6 +12,7 @@ import (
"sync"
"github.com/facebook/ent/examples/o2m2types/ent/pet"
"github.com/facebook/ent/examples/o2m2types/ent/predicate"
"github.com/facebook/ent/examples/o2m2types/ent/user"
"github.com/facebook/ent"
@@ -43,6 +44,7 @@ type PetMutation struct {
clearedowner bool
done bool
oldValue func(context.Context) (*Pet, error)
predicates []predicate.Pet
}
var _ ent.Mutation = (*PetMutation)(nil)
@@ -408,6 +410,7 @@ type UserMutation struct {
clearedpets bool
done bool
oldValue func(context.Context) (*User, error)
predicates []predicate.User
}
var _ ent.Mutation = (*UserMutation)(nil)

View File

@@ -20,14 +20,13 @@ import (
// PetDelete is the builder for deleting a Pet entity.
type PetDelete struct {
config
hooks []Hook
mutation *PetMutation
predicates []predicate.Pet
hooks []Hook
mutation *PetMutation
}
// Where adds a new predicate to the delete builder.
func (pd *PetDelete) Where(ps ...predicate.Pet) *PetDelete {
pd.predicates = append(pd.predicates, ps...)
pd.mutation.predicates = append(pd.mutation.predicates, ps...)
return pd
}
@@ -79,7 +78,7 @@ func (pd *PetDelete) sqlExec(ctx context.Context) (int, error) {
},
},
}
if ps := pd.predicates; len(ps) > 0 {
if ps := pd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)

View File

@@ -21,14 +21,13 @@ import (
// PetUpdate is the builder for updating Pet entities.
type PetUpdate struct {
config
hooks []Hook
mutation *PetMutation
predicates []predicate.Pet
hooks []Hook
mutation *PetMutation
}
// Where adds a new predicate for the builder.
func (pu *PetUpdate) Where(ps ...predicate.Pet) *PetUpdate {
pu.predicates = append(pu.predicates, ps...)
pu.mutation.predicates = append(pu.mutation.predicates, ps...)
return pu
}
@@ -130,7 +129,7 @@ func (pu *PetUpdate) sqlSave(ctx context.Context) (n int, err error) {
},
},
}
if ps := pu.predicates; len(ps) > 0 {
if ps := pu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)

View File

@@ -20,14 +20,13 @@ import (
// UserDelete is the builder for deleting a User entity.
type UserDelete struct {
config
hooks []Hook
mutation *UserMutation
predicates []predicate.User
hooks []Hook
mutation *UserMutation
}
// Where adds a new predicate to the delete builder.
func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete {
ud.predicates = append(ud.predicates, ps...)
ud.mutation.predicates = append(ud.mutation.predicates, ps...)
return ud
}
@@ -79,7 +78,7 @@ func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) {
},
},
}
if ps := ud.predicates; len(ps) > 0 {
if ps := ud.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)

View File

@@ -21,14 +21,13 @@ import (
// UserUpdate is the builder for updating User entities.
type UserUpdate struct {
config
hooks []Hook
mutation *UserMutation
predicates []predicate.User
hooks []Hook
mutation *UserMutation
}
// Where adds a new predicate for the builder.
func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
uu.predicates = append(uu.predicates, ps...)
uu.mutation.predicates = append(uu.mutation.predicates, ps...)
return uu
}
@@ -154,7 +153,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
},
},
}
if ps := uu.predicates; len(ps) > 0 {
if ps := uu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)