mirror of
https://github.com/usememos/memos.git
synced 2025-11-12 10:21:53 +08:00
chore: update condition concat check
This commit is contained in:
parent
64dfadb538
commit
07336f0392
4 changed files with 20 additions and 6 deletions
|
|
@ -121,8 +121,11 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||||
if err := d.ConvertExprToSQL(convertCtx, parsedExpr.GetExpr()); err != nil {
|
if err := d.ConvertExprToSQL(convertCtx, parsedExpr.GetExpr()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
where = append(where, fmt.Sprintf("(%s)", convertCtx.Buffer.String()))
|
condition := convertCtx.Buffer.String()
|
||||||
args = append(args, convertCtx.Args...)
|
if condition != "" {
|
||||||
|
where = append(where, fmt.Sprintf("(%s)", condition))
|
||||||
|
args = append(args, convertCtx.Args...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if find.ExcludeComments {
|
if find.ExcludeComments {
|
||||||
having = append(having, "`parent_id` IS NULL")
|
having = append(having, "`parent_id` IS NULL")
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,11 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||||
if err := d.ConvertExprToSQL(convertCtx, parsedExpr.GetExpr()); err != nil {
|
if err := d.ConvertExprToSQL(convertCtx, parsedExpr.GetExpr()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
where = append(where, fmt.Sprintf("(%s)", convertCtx.Buffer.String()))
|
condition := convertCtx.Buffer.String()
|
||||||
args = append(args, convertCtx.Args...)
|
if condition != "" {
|
||||||
|
where = append(where, fmt.Sprintf("(%s)", condition))
|
||||||
|
args = append(args, convertCtx.Args...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if find.ExcludeComments {
|
if find.ExcludeComments {
|
||||||
where = append(where, "memo_relation.related_memo_id IS NULL")
|
where = append(where, "memo_relation.related_memo_id IS NULL")
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,11 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||||
if err := d.ConvertExprToSQL(convertCtx, parsedExpr.GetExpr()); err != nil {
|
if err := d.ConvertExprToSQL(convertCtx, parsedExpr.GetExpr()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
where = append(where, fmt.Sprintf("(%s)", convertCtx.Buffer.String()))
|
condition := convertCtx.Buffer.String()
|
||||||
args = append(args, convertCtx.Args...)
|
if condition != "" {
|
||||||
|
where = append(where, fmt.Sprintf("(%s)", condition))
|
||||||
|
args = append(args, convertCtx.Args...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if find.ExcludeComments {
|
if find.ExcludeComments {
|
||||||
where = append(where, "`parent_id` IS NULL")
|
where = append(where, "`parent_id` IS NULL")
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,11 @@ func TestConvertExprToSQL(t *testing.T) {
|
||||||
want: "(JSON_EXTRACT(`memo`.`payload`, '$.tags') LIKE ? OR `memo`.`content` LIKE ?)",
|
want: "(JSON_EXTRACT(`memo`.`payload`, '$.tags') LIKE ? OR `memo`.`content` LIKE ?)",
|
||||||
args: []any{`%"tag1"%`, "%hello%"},
|
args: []any{`%"tag1"%`, "%hello%"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
filter: `1`,
|
||||||
|
want: "",
|
||||||
|
args: []any{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue