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/o2orecur/ent/node"
"github.com/facebook/ent/examples/o2orecur/ent/predicate"
"github.com/facebook/ent"
)
@@ -44,6 +45,7 @@ type NodeMutation struct {
clearednext bool
done bool
oldValue func(context.Context) (*Node, error)
predicates []predicate.Node
}
var _ ent.Mutation = (*NodeMutation)(nil)

View File

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