fix: memo filter for postgres
This commit is contained in:
parent
f5d5ebea6f
commit
3cc0e255ce
2 changed files with 7 additions and 7 deletions
|
|
@ -160,7 +160,7 @@ func (d *DB) ConvertExprToSQL(ctx *filter.ConvertContext, expr *exprv1.Expr) err
|
||||||
subcodition := []string{}
|
subcodition := []string{}
|
||||||
args := []any{}
|
args := []any{}
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
subcodition, args = append(subcodition, fmt.Sprintf(`memo.payload->'tags' @> %s::jsonb`, placeholder(len(ctx.Args)+ctx.ArgsOffset+len(args)+1))), append(args, []any{v})
|
subcodition, args = append(subcodition, fmt.Sprintf(`memo.payload->'tags' @> jsonb_build_array(%s)`, placeholder(len(ctx.Args)+ctx.ArgsOffset+len(args)+1))), append(args, v)
|
||||||
}
|
}
|
||||||
if len(subcodition) == 1 {
|
if len(subcodition) == 1 {
|
||||||
if _, err := ctx.Buffer.WriteString(subcodition[0]); err != nil {
|
if _, err := ctx.Buffer.WriteString(subcodition[0]); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@ func TestRestoreExprToSQL(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
filter: `tag in ["tag1", "tag2"]`,
|
filter: `tag in ["tag1", "tag2"]`,
|
||||||
want: "(memo.payload->'tags' @> $1::jsonb OR memo.payload->'tags' @> $2::jsonb)",
|
want: "(memo.payload->'tags' @> jsonb_build_array($1) OR memo.payload->'tags' @> jsonb_build_array($2))",
|
||||||
args: []any{[]any{"tag1"}, []any{"tag2"}},
|
args: []any{"tag1", "tag2"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `!(tag in ["tag1", "tag2"])`,
|
filter: `!(tag in ["tag1", "tag2"])`,
|
||||||
want: `NOT ((memo.payload->'tags' @> $1::jsonb OR memo.payload->'tags' @> $2::jsonb))`,
|
want: `NOT ((memo.payload->'tags' @> jsonb_build_array($1) OR memo.payload->'tags' @> jsonb_build_array($2)))`,
|
||||||
args: []any{[]any{"tag1"}, []any{"tag2"}},
|
args: []any{"tag1", "tag2"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `content.contains("memos")`,
|
filter: `content.contains("memos")`,
|
||||||
|
|
@ -46,8 +46,8 @@ func TestRestoreExprToSQL(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `tag in ['tag1'] || content.contains('hello')`,
|
filter: `tag in ['tag1'] || content.contains('hello')`,
|
||||||
want: "(memo.payload->'tags' @> $1::jsonb OR memo.content ILIKE $2)",
|
want: "(memo.payload->'tags' @> jsonb_build_array($1) OR memo.content ILIKE $2)",
|
||||||
args: []any{[]any{"tag1"}, "%hello%"},
|
args: []any{"tag1", "%hello%"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `1`,
|
filter: `1`,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue