mirror of
https://github.com/usememos/memos.git
synced 2025-12-17 14:19:17 +08:00
- Updated memo and reaction filtering logic to use a unified engine for compiling filter expressions into SQL statements. - Removed redundant filter parsing and conversion code from ListMemoRelations, ListReactions, and ListAttachments methods. - Introduced IDList and UIDList fields in FindMemo and FindReaction structs to support filtering by multiple IDs. - Removed old filter test files for reactions and attachments, as the filtering logic has been centralized. - Updated tests for memo filtering to reflect the new SQL statement compilation approach. - Ensured that unsupported user filters return an error in ListUsers method.
25 lines
647 B
Go
25 lines
647 B
Go
package filter
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// AppendConditions compiles the provided filters and appends the resulting SQL fragments and args.
|
|
func AppendConditions(ctx context.Context, engine *Engine, filters []string, dialect DialectName, where *[]string, args *[]any) error {
|
|
for _, filterStr := range filters {
|
|
stmt, err := engine.CompileToStatement(ctx, filterStr, RenderOptions{
|
|
Dialect: dialect,
|
|
PlaceholderOffset: len(*args),
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if stmt.SQL == "" {
|
|
continue
|
|
}
|
|
*where = append(*where, fmt.Sprintf("(%s)", stmt.SQL))
|
|
*args = append(*args, stmt.Args...)
|
|
}
|
|
return nil
|
|
}
|