Merge pull request #425 from dalefengs/fix_group

fix: 渠道多分组查询 sqlite 查询兼容
This commit is contained in:
Calcium-Ion 2024-08-09 15:44:23 +08:00 committed by GitHub
commit e495354823
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -108,10 +108,11 @@ func SearchChannels(keyword string, group string, model string) ([]*Channel, err
var args []interface{} var args []interface{}
if group != "" && group != "null" { if group != "" && group != "null" {
var groupCondition string var groupCondition string
if common.UsingPostgreSQL { if common.UsingMySQL {
groupCondition = `(',' || ` + groupCol + ` || ',') LIKE ?`
} else {
groupCondition = `CONCAT(',', ` + groupCol + `, ',') LIKE ?` groupCondition = `CONCAT(',', ` + groupCol + `, ',') LIKE ?`
} else {
// sqlite, PostgreSQL
groupCondition = `(',' || ` + groupCol + ` || ',') LIKE ?`
} }
whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + ` LIKE ? AND ` + groupCondition whereClause = "(id = ? OR name LIKE ? OR " + keyCol + " = ?) AND " + modelsCol + ` LIKE ? AND ` + groupCondition
args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%", "%,"+group+",%") args = append(args, common.String2Int(keyword), "%"+keyword+"%", keyword, "%"+model+"%", "%,"+group+",%")
@ -121,7 +122,7 @@ func SearchChannels(keyword string, group string, model string) ([]*Channel, err
} }
// 执行查询 // 执行查询
err := baseQuery.Where(whereClause, args...).Find(&channels).Error err := baseQuery.Where(whereClause, args...).Order("priority desc").Find(&channels).Error
if err != nil { if err != nil {
return nil, err return nil, err
} }