1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

fix: invalid search query in Postgres

This commit is contained in:
Miles Liu 2023-05-15 13:46:45 +08:00
parent 8de56a4c7b
commit 74390bfccf
No known key found for this signature in database
GPG Key ID: 4DB9B32F9B24A7A9

View File

@ -2,6 +2,7 @@ package repositories
import (
"errors"
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
@ -36,8 +37,12 @@ func (r *KeyValueRepository) GetString(key string) (*models.KeyStringValue, erro
func (r *KeyValueRepository) Search(like string) ([]*models.KeyStringValue, error) {
var keyValues []*models.KeyStringValue
condition := "key like ?"
if r.db.Config.Name() == config.SQLDialectMysql {
condition = "`key` like ?"
}
if err := r.db.Table("key_string_values").
Where("`key` like ?", like).
Where(condition, like).
Find(&keyValues).
Error; err != nil {
return nil, err