Skip to content

Commit

Permalink
fix: invalid search query in Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
miles170 committed May 15, 2023
1 parent 8de56a4 commit 74390bf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion repositories/key_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 74390bf

Please sign in to comment.