mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-02-02 09:48:13 -05:00
Another tweak for postgres sigh
This commit is contained in:
parent
4b4c7baea4
commit
63845377d9
@ -25,3 +25,14 @@ func QuoteTableName(tbl string) string {
|
|||||||
return fmt.Sprintf("`%s`", tbl)
|
return fmt.Sprintf("`%s`", tbl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCaseInsensitiveLike returns a different operator based on
|
||||||
|
// the db driver
|
||||||
|
func GetCaseInsensitiveLike() string {
|
||||||
|
switch strings.ToLower(config.Configuration.DB.Driver) {
|
||||||
|
case config.DatabasePostgres:
|
||||||
|
return "ILIKE"
|
||||||
|
default:
|
||||||
|
return "LIKE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"npm/internal/database"
|
||||||
"npm/internal/model"
|
"npm/internal/model"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -37,6 +38,7 @@ func ScopeOrderBy(pageInfo *model.PageInfo, defaultSort model.Sort) func(db *gor
|
|||||||
|
|
||||||
func ScopeFilters(filters []model.Filter, filterMap map[string]filterMapValue) func(db *gorm.DB) *gorm.DB {
|
func ScopeFilters(filters []model.Filter, filterMap map[string]filterMapValue) func(db *gorm.DB) *gorm.DB {
|
||||||
return func(db *gorm.DB) *gorm.DB {
|
return func(db *gorm.DB) *gorm.DB {
|
||||||
|
like := database.GetCaseInsensitiveLike()
|
||||||
for _, f := range filters {
|
for _, f := range filters {
|
||||||
// Lookup this filter field from the name map
|
// Lookup this filter field from the name map
|
||||||
if _, ok := filterMap[f.Field]; ok {
|
if _, ok := filterMap[f.Field]; ok {
|
||||||
@ -69,11 +71,11 @@ func ScopeFilters(filters []model.Filter, filterMap map[string]filterMapValue) f
|
|||||||
|
|
||||||
// LIKE modifiers:
|
// LIKE modifiers:
|
||||||
case "contains":
|
case "contains":
|
||||||
db.Where(fmt.Sprintf("%s LIKE ?", f.Field), `%`+f.Value[0]+`%`)
|
db.Where(fmt.Sprintf("%s %s ?", f.Field, like), `%`+f.Value[0]+`%`)
|
||||||
case "starts":
|
case "starts":
|
||||||
db.Where(fmt.Sprintf("%s LIKE ?", f.Field), f.Value[0]+`%`)
|
db.Where(fmt.Sprintf("%s %s ?", f.Field, like), f.Value[0]+`%`)
|
||||||
case "ends":
|
case "ends":
|
||||||
db.Where(fmt.Sprintf("%s LIKE ?", f.Field), `%`+f.Value[0])
|
db.Where(fmt.Sprintf("%s %s ?", f.Field, like), `%`+f.Value[0])
|
||||||
|
|
||||||
// Array parameter modifiers:
|
// Array parameter modifiers:
|
||||||
case "in":
|
case "in":
|
||||||
|
Loading…
Reference in New Issue
Block a user