|
|
|
@ -2,8 +2,10 @@ package sqlite
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/usememos/memos/plugin/filter"
|
|
|
|
|
"github.com/usememos/memos/store"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -46,6 +48,25 @@ func (d *DB) ListMemoRelations(ctx context.Context, find *store.FindMemoRelation
|
|
|
|
|
if find.Type != nil {
|
|
|
|
|
where, args = append(where, "type = ?"), append(args, find.Type)
|
|
|
|
|
}
|
|
|
|
|
if find.MemoFilter != nil {
|
|
|
|
|
// Parse filter string and return the parsed expression.
|
|
|
|
|
// The filter string should be a CEL expression.
|
|
|
|
|
parsedExpr, err := filter.Parse(*find.MemoFilter, filter.MemoFilterCELAttributes...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
convertCtx := filter.NewConvertContext()
|
|
|
|
|
// ConvertExprToSQL converts the parsed expression to a SQL condition string.
|
|
|
|
|
if err := d.ConvertExprToSQL(convertCtx, parsedExpr.GetExpr()); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
condition := convertCtx.Buffer.String()
|
|
|
|
|
if condition != "" {
|
|
|
|
|
where = append(where, fmt.Sprintf("memo_id IN (SELECT id FROM memo WHERE %s)", condition))
|
|
|
|
|
where = append(where, fmt.Sprintf("related_memo_id IN (SELECT id FROM memo WHERE %s)", condition))
|
|
|
|
|
args = append(args, append(convertCtx.Args, convertCtx.Args...)...)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rows, err := d.db.QueryContext(ctx, `
|
|
|
|
|
SELECT
|
|
|
|
|