Skip to content

Commit

Permalink
add Lower() and Upper() methods to string expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
lqs committed Mar 29, 2023
1 parent 8cb2a72 commit 8a14d1b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -108,6 +110,8 @@ type UnknownExpression interface {
Concat(other interface{}) StringExpression
IfEmpty(altValue interface{}) StringExpression
IsEmpty() BooleanExpression
Lower() StringExpression
Upper() StringExpression
}

type expression struct {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8a14d1b

Please sign in to comment.