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

@@ -20,14 +20,13 @@ import (
// CityDelete is the builder for deleting a City entity.
type CityDelete struct {
config
hooks []Hook
mutation *CityMutation
predicates []predicate.City
hooks []Hook
mutation *CityMutation
}
// Where adds a new predicate to the delete builder.
func (cd *CityDelete) Where(ps ...predicate.City) *CityDelete {
cd.predicates = append(cd.predicates, ps...)
cd.mutation.predicates = append(cd.mutation.predicates, ps...)
return cd
}
@@ -79,7 +78,7 @@ func (cd *CityDelete) sqlExec(ctx context.Context) (int, error) {
},
},
}
if ps := cd.predicates; len(ps) > 0 {
if ps := cd.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 (
// CityUpdate is the builder for updating City entities.
type CityUpdate struct {
config
hooks []Hook
mutation *CityMutation
predicates []predicate.City
hooks []Hook
mutation *CityMutation
}
// Where adds a new predicate for the builder.
func (cu *CityUpdate) Where(ps ...predicate.City) *CityUpdate {
cu.predicates = append(cu.predicates, ps...)
cu.mutation.predicates = append(cu.mutation.predicates, ps...)
return cu
}
@@ -141,7 +140,7 @@ func (cu *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
},
},
}
if ps := cu.predicates; len(ps) > 0 {
if ps := cu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)

View File

@@ -12,6 +12,7 @@ import (
"sync"
"github.com/facebook/ent/examples/edgeindex/ent/city"
"github.com/facebook/ent/examples/edgeindex/ent/predicate"
"github.com/facebook/ent/examples/edgeindex/ent/street"
"github.com/facebook/ent"
@@ -44,6 +45,7 @@ type CityMutation struct {
clearedstreets bool
done bool
oldValue func(context.Context) (*City, error)
predicates []predicate.City
}
var _ ent.Mutation = (*CityMutation)(nil)
@@ -428,6 +430,7 @@ type StreetMutation struct {
clearedcity bool
done bool
oldValue func(context.Context) (*Street, error)
predicates []predicate.Street
}
var _ ent.Mutation = (*StreetMutation)(nil)

View File

@@ -20,14 +20,13 @@ import (
// StreetDelete is the builder for deleting a Street entity.
type StreetDelete struct {
config
hooks []Hook
mutation *StreetMutation
predicates []predicate.Street
hooks []Hook
mutation *StreetMutation
}
// Where adds a new predicate to the delete builder.
func (sd *StreetDelete) Where(ps ...predicate.Street) *StreetDelete {
sd.predicates = append(sd.predicates, ps...)
sd.mutation.predicates = append(sd.mutation.predicates, ps...)
return sd
}
@@ -79,7 +78,7 @@ func (sd *StreetDelete) sqlExec(ctx context.Context) (int, error) {
},
},
}
if ps := sd.predicates; len(ps) > 0 {
if ps := sd.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 (
// StreetUpdate is the builder for updating Street entities.
type StreetUpdate struct {
config
hooks []Hook
mutation *StreetMutation
predicates []predicate.Street
hooks []Hook
mutation *StreetMutation
}
// Where adds a new predicate for the builder.
func (su *StreetUpdate) Where(ps ...predicate.Street) *StreetUpdate {
su.predicates = append(su.predicates, ps...)
su.mutation.predicates = append(su.mutation.predicates, ps...)
return su
}
@@ -130,7 +129,7 @@ func (su *StreetUpdate) sqlSave(ctx context.Context) (n int, err error) {
},
},
}
if ps := su.predicates; len(ps) > 0 {
if ps := su.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)