mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
dialect/sql: add predicates for composite where query (#264)
* add predicates for composite where query Signed-off-by: Christoph Hartmann <chris@lollyrock.com> * use existing table.Columns method * simplify the composite operator methods
This commit is contained in:
committed by
Ariel Mashraki
parent
0dfc9954a3
commit
46982d2f05
@@ -1061,6 +1061,38 @@ func (p *Predicate) ContainsFold(col, sub string) *Predicate {
|
||||
})
|
||||
}
|
||||
|
||||
func CompositeGT(columns []string, args ...interface{}) *Predicate {
|
||||
return (&Predicate{}).CompositeGT(columns, args...)
|
||||
}
|
||||
|
||||
func CompositeLT(columns []string, args ...interface{}) *Predicate {
|
||||
return (&Predicate{}).CompositeLT(columns, args...)
|
||||
}
|
||||
|
||||
func (p *Predicate) compositeP(operator string, columns []string, args ...interface{}) *Predicate {
|
||||
return p.append(func(b *Builder) {
|
||||
b.Nested(func(nb *Builder) {
|
||||
nb.IdentComma(columns...)
|
||||
})
|
||||
b.WriteString(operator)
|
||||
b.WriteString("(")
|
||||
b.Args(args...)
|
||||
b.WriteString(")")
|
||||
})
|
||||
}
|
||||
|
||||
// GT returns a composite ">" predicate.
|
||||
func (p *Predicate) CompositeGT(columns []string, args ...interface{}) *Predicate {
|
||||
const operator = " > "
|
||||
return p.compositeP(operator, columns, args...)
|
||||
}
|
||||
|
||||
// LT appends a composite "<" predicate.
|
||||
func (p *Predicate) CompositeLT(columns []string, args ...interface{}) *Predicate {
|
||||
const operator = " < "
|
||||
return p.compositeP(operator, columns, args...)
|
||||
}
|
||||
|
||||
// Query returns query representation of a predicate.
|
||||
func (p *Predicate) Query() (string, []interface{}) {
|
||||
for _, f := range p.fns {
|
||||
|
||||
Reference in New Issue
Block a user