mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
ent: add AND operator for type predicates
Reviewed By: alexsn Differential Revision: D16668249 fbshipit-source-id: 1554c3af9779fd551a90218c604d23b5bf8b8c6b
This commit is contained in:
committed by
Facebook Github Bot
parent
4565455ee4
commit
2fd1b728f3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user