ent: add AND operator for type predicates

Reviewed By: alexsn

Differential Revision: D16668249

fbshipit-source-id: 1554c3af9779fd551a90218c604d23b5bf8b8c6b
This commit is contained in:
Ariel Mashraki
2019-08-06 14:38:28 -07:00
committed by Facebook Github Bot
parent 4565455ee4
commit 2fd1b728f3
20 changed files with 348 additions and 71 deletions

View File

@@ -359,7 +359,27 @@ func HasNextWith(preds ...predicate.Node) predicate.Node {
)
}
// Or groups list of predicates with the or operator between them.
// And groups list of predicates with the AND operator between them.
func And(predicates ...predicate.Node) predicate.Node {
return predicate.NodePerDialect(
func(s *sql.Selector) {
for _, p := range predicates {
p(s)
}
},
func(tr *dsl.Traversal) {
trs := make([]interface{}, 0, len(predicates))
for _, p := range predicates {
t := __.New()
p(t)
trs = append(trs, t)
}
tr.Where(__.And(trs...))
},
)
}
// Or groups list of predicates with the OR operator between them.
func Or(predicates ...predicate.Node) predicate.Node {
return predicate.NodePerDialect(
func(s *sql.Selector) {