Skip to content

Commit

Permalink
enhance #85:builder supports uppercase operators (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
cncal authored Jul 6, 2020
1 parent aa576ce commit e92ac15
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 136 deletions.
2 changes: 1 addition & 1 deletion builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {

sign: `BuildSelect(table string, where map[string]interface{}, field []string) (string,[]interface{},error)`

operators supported:
operators supported(case-insensitive):

* =
* >
Expand Down
9 changes: 5 additions & 4 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func resolveHaving(having interface{}) (map[string]interface{}, error) {
if nil != err {
return nil, err
}
if !isStringInSlice(operator, opOrder) {
if !isStringInSlice(strings.ToLower(operator), opOrder) {
return nil, errHavingUnsupportedOperator
}
copiedMap[key] = val
Expand Down Expand Up @@ -228,12 +228,13 @@ func getWhereConditions(where map[string]interface{}) ([]Comparable, error) {
continue
}
field, operator, err = splitKey(key)
if !isStringInSlice(operator, opOrder) {
return nil, ErrUnsupportedOperator
}
if nil != err {
return nil, err
}
operator = strings.ToLower(operator)
if !isStringInSlice(operator, opOrder) {
return nil, ErrUnsupportedOperator
}
if _, ok := val.(NullType); ok {
operator = opNull
}
Expand Down
Loading

0 comments on commit e92ac15

Please sign in to comment.