mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: memo filter for postgres
This commit is contained in:
@@ -160,7 +160,7 @@ func (d *DB) ConvertExprToSQL(ctx *filter.ConvertContext, expr *exprv1.Expr) err
|
||||
subcodition := []string{}
|
||||
args := []any{}
|
||||
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 _, err := ctx.Buffer.WriteString(subcodition[0]); err != nil {
|
||||
|
@@ -16,13 +16,13 @@ func TestRestoreExprToSQL(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
filter: `tag in ["tag1", "tag2"]`,
|
||||
want: "(memo.payload->'tags' @> $1::jsonb OR memo.payload->'tags' @> $2::jsonb)",
|
||||
args: []any{[]any{"tag1"}, []any{"tag2"}},
|
||||
want: "(memo.payload->'tags' @> jsonb_build_array($1) OR memo.payload->'tags' @> jsonb_build_array($2))",
|
||||
args: []any{"tag1", "tag2"},
|
||||
},
|
||||
{
|
||||
filter: `!(tag in ["tag1", "tag2"])`,
|
||||
want: `NOT ((memo.payload->'tags' @> $1::jsonb OR memo.payload->'tags' @> $2::jsonb))`,
|
||||
args: []any{[]any{"tag1"}, []any{"tag2"}},
|
||||
want: `NOT ((memo.payload->'tags' @> jsonb_build_array($1) OR memo.payload->'tags' @> jsonb_build_array($2)))`,
|
||||
args: []any{"tag1", "tag2"},
|
||||
},
|
||||
{
|
||||
filter: `content.contains("memos")`,
|
||||
@@ -46,8 +46,8 @@ func TestRestoreExprToSQL(t *testing.T) {
|
||||
},
|
||||
{
|
||||
filter: `tag in ['tag1'] || content.contains('hello')`,
|
||||
want: "(memo.payload->'tags' @> $1::jsonb OR memo.content ILIKE $2)",
|
||||
args: []any{[]any{"tag1"}, "%hello%"},
|
||||
want: "(memo.payload->'tags' @> jsonb_build_array($1) OR memo.content ILIKE $2)",
|
||||
args: []any{"tag1", "%hello%"},
|
||||
},
|
||||
{
|
||||
filter: `1`,
|
||||
|
Reference in New Issue
Block a user