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 (
// CardDelete is the builder for deleting a Card entity.
type CardDelete struct {
config
hooks []Hook
mutation *CardMutation
predicates []predicate.Card
hooks []Hook
mutation *CardMutation
}
// Where adds a new predicate to the delete builder.
func (cd *CardDelete) Where(ps ...predicate.Card) *CardDelete {
cd.predicates = append(cd.predicates, ps...)
cd.mutation.predicates = append(cd.mutation.predicates, ps...)
return cd
}
@@ -79,7 +78,7 @@ func (cd *CardDelete) 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

@@ -23,14 +23,13 @@ import (
// CardUpdate is the builder for updating Card entities.
type CardUpdate struct {
config
hooks []Hook
mutation *CardMutation
predicates []predicate.Card
hooks []Hook
mutation *CardMutation
}
// Where adds a new predicate for the builder.
func (cu *CardUpdate) Where(ps ...predicate.Card) *CardUpdate {
cu.predicates = append(cu.predicates, ps...)
cu.mutation.predicates = append(cu.mutation.predicates, ps...)
return cu
}
@@ -144,7 +143,7 @@ func (cu *CardUpdate) 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

@@ -13,6 +13,7 @@ import (
"time"
"github.com/facebook/ent/examples/o2o2types/ent/card"
"github.com/facebook/ent/examples/o2o2types/ent/predicate"
"github.com/facebook/ent/examples/o2o2types/ent/user"
"github.com/facebook/ent"
@@ -45,6 +46,7 @@ type CardMutation struct {
clearedowner bool
done bool
oldValue func(context.Context) (*Card, error)
predicates []predicate.Card
}
var _ ent.Mutation = (*CardMutation)(nil)
@@ -463,6 +465,7 @@ type UserMutation struct {
clearedcard bool
done bool
oldValue func(context.Context) (*User, error)
predicates []predicate.User
}
var _ ent.Mutation = (*UserMutation)(nil)

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
}
@@ -143,7 +142,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)