diff --git a/dbHandler.go b/dbHandler.go index 1e0dd96..ae0f81e 100644 --- a/dbHandler.go +++ b/dbHandler.go @@ -182,8 +182,22 @@ func (dH *DBHandler) GetByKey(model any, key string, value any, LikeSearch bool, query = query.Preload(relation) } 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), "*", "%") 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 }