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
1 changed files with 6 additions and 1 deletions

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