diff --git a/expression.go b/expression.go index 4144075..06134da 100644 --- a/expression.go +++ b/expression.go @@ -82,6 +82,8 @@ type StringExpression interface { Concat(other interface{}) StringExpression IfEmpty(altValue interface{}) StringExpression IsEmpty() BooleanExpression + Lower() StringExpression + Upper() StringExpression } // UnknownExpression is the interface of an SQL expression with unknown value. @@ -108,6 +110,8 @@ type UnknownExpression interface { Concat(other interface{}) StringExpression IfEmpty(altValue interface{}) StringExpression IsEmpty() BooleanExpression + Lower() StringExpression + Upper() StringExpression } type expression struct { @@ -215,6 +219,14 @@ func (e expression) IsEmpty() BooleanExpression { return e.Equals("") } +func (e expression) Lower() StringExpression { + return function("LOWER", e) +} + +func (e expression) Upper() StringExpression { + return function("UPPER", e) +} + func (e expression) GetSQL(scope scope) (string, error) { if e.sql != "" { return e.sql, nil diff --git a/expression_test.go b/expression_test.go index 9fb24e5..ef6d36f 100644 --- a/expression_test.go +++ b/expression_test.go @@ -115,6 +115,8 @@ func TestFunc(t *testing.T) { assertValue(t, e.IfNull(3), "IFNULL(<>, 3)") assertValue(t, e.IfEmpty(3), "IF(<> <> '', <>, 3)") assertValue(t, e.IsEmpty(), "<> = ''") + assertValue(t, e.Lower(), "LOWER(<>)") + assertValue(t, e.Upper(), "UPPER(<>)") e5 := expression{ builder: func(scope scope) (string, error) {