Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e45a20b6a |
14
dbHandler.go
14
dbHandler.go
@@ -182,8 +182,22 @@ func (dH *DBHandler) GetByKey(model any, key string, value any, LikeSearch bool,
|
|||||||
query = query.Preload(relation)
|
query = query.Preload(relation)
|
||||||
}
|
}
|
||||||
if LikeSearch {
|
if LikeSearch {
|
||||||
|
if vals, ok := value.([]string); ok {
|
||||||
|
subQuery := dH.db
|
||||||
|
for i, v := range vals {
|
||||||
|
v = strings.ReplaceAll(v, "*", "%")
|
||||||
|
if i == 0 {
|
||||||
|
subQuery = subQuery.Where(key+" LIKE ?", v)
|
||||||
|
} else {
|
||||||
|
subQuery = subQuery.Or(key+" LIKE ?", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return query.Where(subQuery).Find(model).Error
|
||||||
|
}
|
||||||
|
|
||||||
value = strings.ReplaceAll(fmt.Sprint(value), "*", "%")
|
value = strings.ReplaceAll(fmt.Sprint(value), "*", "%")
|
||||||
dH.logger.Debug("getByKey", "find like key "+key+" value "+fmt.Sprint(value))
|
dH.logger.Debug("getByKey", "find like key "+key+" value "+fmt.Sprint(value))
|
||||||
|
fmt.Println(465, "find like key "+key+" value "+fmt.Sprint(value))
|
||||||
return query.Where(key+" LIKE ?", value).Find(model).Error
|
return query.Where(key+" LIKE ?", value).Find(model).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user