Skip to content

Commit

Permalink
fix: fixing query filter for gorm support number and boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
prakasa1904 committed Nov 3, 2024
1 parent 2d34b5d commit 897af02
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions gormmer/query_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gormmer

import (
"net/url"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -36,12 +35,16 @@ func ConvertQueryToFilter(url *url.URL, allowFilterQuery []string) map[string]st
for key, val := range url.Query() {
for _, allowKey := range allowFilterQuery {
if allowKey == key {
isNumeric := regexp.MustCompile(`\d`).MatchString(val[0])

if isNumeric {
_, err := strconv.Atoi(val[0])
if err == nil {
filter[key+" = ?"] = val[0]
} else {
filter[key+" LIKE ?"] = "%" + val[0] + "%"
_, err := strconv.ParseBool(val[0])
if err == nil {
filter[key+" = ?"] = val[0]
} else {
filter[key+" LIKE ?"] = "%" + val[0] + "%"
}
}
}
}
Expand Down

0 comments on commit 897af02

Please sign in to comment.