|
|
|
|
@ -41,6 +41,25 @@ func (d *DB) CreateMemo(ctx context.Context, create *store.Memo) (*store.Memo, e
|
|
|
|
|
func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo, error) {
|
|
|
|
|
where, args := []string{"1 = 1"}, []any{}
|
|
|
|
|
|
|
|
|
|
for _, filterStr := range find.Filters {
|
|
|
|
|
// Parse filter string and return the parsed expression.
|
|
|
|
|
// The filter string should be a CEL expression.
|
|
|
|
|
parsedExpr, err := filter.Parse(filterStr, filter.MemoFilterCELAttributes...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
convertCtx := filter.NewConvertContext()
|
|
|
|
|
convertCtx.ArgsOffset = len(args)
|
|
|
|
|
// 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("(%s)", condition))
|
|
|
|
|
args = append(args, convertCtx.Args...)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v := find.ID; v != nil {
|
|
|
|
|
where, args = append(where, "memo.id = "+placeholder(len(args)+1)), append(args, *v)
|
|
|
|
|
}
|
|
|
|
|
@ -103,25 +122,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
|
|
|
|
where = append(where, "(memo.payload->'property'->>'hasIncompleteTasks')::BOOLEAN IS TRUE")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if v := find.Filter; v != nil {
|
|
|
|
|
// Parse filter string and return the parsed expression.
|
|
|
|
|
// The filter string should be a CEL expression.
|
|
|
|
|
parsedExpr, err := filter.Parse(*v, filter.MemoFilterCELAttributes...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
convertCtx := filter.NewConvertContext()
|
|
|
|
|
convertCtx.ArgsOffset = len(args)
|
|
|
|
|
// 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("(%s)", condition))
|
|
|
|
|
args = append(args, convertCtx.Args...)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if find.ExcludeComments {
|
|
|
|
|
where = append(where, "memo_relation.related_memo_id IS NULL")
|
|
|
|
|
}
|
|
|
|
|
|