ent/dialect/sql: add upper and lower methods

Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/18

Reviewed By: elys1um

Differential Revision: D16916563

fbshipit-source-id: f758536103356cb5b2bacf707c7c7da931bb4560
This commit is contained in:
Ariel Mashraki
2019-08-20 07:51:45 -07:00
committed by Facebook Github Bot
parent 85d2d6adcd
commit e2524ff0ad
2 changed files with 50 additions and 0 deletions

View File

@@ -1028,6 +1028,32 @@ func (p *Predicate) Contains(col, sub string) *Predicate {
return p.Like(col, "%"+sub+"%")
}
// Lower wraps the given column with the LOWER function.
//
// P().EQ(sql.Lower("name"), "a8m")
//
func Lower(name string) string {
var b Builder
b.WriteString("LOWER")
b.Nested(func(b *Builder) {
b.Append(name)
})
return b.String()
}
// Upper wraps the given column with the UPPER function.
//
// P().EQ(sql.Upper("name"), "a8m")
//
func Upper(name string) string {
var b Builder
b.WriteString("UPPER")
b.Nested(func(b *Builder) {
b.Append(name)
})
return b.String()
}
// Query returns query representation of a predicate.
func (p *Predicate) Query() (string, []interface{}) {
return p.b.String(), p.b.args