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

@@ -11,6 +11,7 @@ import (
"fmt"
"sync"
"github.com/facebook/ent/examples/m2mbidi/ent/predicate"
"github.com/facebook/ent/examples/m2mbidi/ent/user"
"github.com/facebook/ent"
@@ -44,6 +45,7 @@ type UserMutation struct {
clearedfriends 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

@@ -20,14 +20,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
}
@@ -153,7 +152,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)