mirror of
https://github.com/usememos/memos.git
synced 2025-11-10 01:10:52 +08:00
feat: support more operators in filter
This commit is contained in:
parent
03189ee3b2
commit
ff04fdc459
3 changed files with 59 additions and 2 deletions
|
|
@ -102,6 +102,25 @@ func ConvertExprToSQL(ctx *filter.ConvertContext, expr *exprv1.Expr) error {
|
|||
return err
|
||||
}
|
||||
ctx.Args = append(ctx.Args, timestamp.Unix())
|
||||
} else if identifier == "visibility" || identifier == "content" {
|
||||
if operator != "=" && operator != "!=" {
|
||||
return errors.Errorf("invalid operator for %s", v.CallExpr.Function)
|
||||
}
|
||||
valueStr, ok := value.(string)
|
||||
if !ok {
|
||||
return errors.New("invalid string value")
|
||||
}
|
||||
|
||||
var factor string
|
||||
if identifier == "visibility" {
|
||||
factor = "`memo`.`visibility`"
|
||||
} else if identifier == "content" {
|
||||
factor = "`memo`.`content`"
|
||||
}
|
||||
if _, err := ctx.Buffer.WriteString(fmt.Sprintf("%s %s ?", factor, operator)); err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.Args = append(ctx.Args, valueStr)
|
||||
}
|
||||
case "@in":
|
||||
if len(v.CallExpr.Args) != 2 {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func ConvertExprToSQL(ctx *filter.ConvertContext, expr *exprv1.Expr) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !slices.Contains([]string{"create_time", "update_time"}, identifier) {
|
||||
if !slices.Contains([]string{"create_time", "update_time", "visibility", "content"}, identifier) {
|
||||
return errors.Errorf("invalid identifier for %s", v.CallExpr.Function)
|
||||
}
|
||||
value, err := filter.GetConstValue(v.CallExpr.Args[1])
|
||||
|
|
@ -102,6 +102,25 @@ func ConvertExprToSQL(ctx *filter.ConvertContext, expr *exprv1.Expr) error {
|
|||
return err
|
||||
}
|
||||
ctx.Args = append(ctx.Args, timestamp.Unix())
|
||||
} else if identifier == "visibility" || identifier == "content" {
|
||||
if operator != "=" && operator != "!=" {
|
||||
return errors.Errorf("invalid operator for %s", v.CallExpr.Function)
|
||||
}
|
||||
valueStr, ok := value.(string)
|
||||
if !ok {
|
||||
return errors.New("invalid string value")
|
||||
}
|
||||
|
||||
var factor string
|
||||
if identifier == "visibility" {
|
||||
factor = "memo.visibility"
|
||||
} else if identifier == "content" {
|
||||
factor = "memo.content"
|
||||
}
|
||||
if _, err := ctx.Buffer.WriteString(fmt.Sprintf("%s %s %s", factor, operator, placeholder(len(ctx.Args)+ctx.ArgsOffset+1))); err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.Args = append(ctx.Args, valueStr)
|
||||
}
|
||||
case "@in":
|
||||
if len(v.CallExpr.Args) != 2 {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func ConvertExprToSQL(ctx *filter.ConvertContext, expr *exprv1.Expr) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !slices.Contains([]string{"create_time", "update_time"}, identifier) {
|
||||
if !slices.Contains([]string{"create_time", "update_time", "visibility", "content"}, identifier) {
|
||||
return errors.Errorf("invalid identifier for %s", v.CallExpr.Function)
|
||||
}
|
||||
value, err := filter.GetConstValue(v.CallExpr.Args[1])
|
||||
|
|
@ -102,6 +102,25 @@ func ConvertExprToSQL(ctx *filter.ConvertContext, expr *exprv1.Expr) error {
|
|||
return err
|
||||
}
|
||||
ctx.Args = append(ctx.Args, timestamp.Unix())
|
||||
} else if identifier == "visibility" || identifier == "content" {
|
||||
if operator != "=" && operator != "!=" {
|
||||
return errors.Errorf("invalid operator for %s", v.CallExpr.Function)
|
||||
}
|
||||
valueStr, ok := value.(string)
|
||||
if !ok {
|
||||
return errors.New("invalid string value")
|
||||
}
|
||||
|
||||
var factor string
|
||||
if identifier == "visibility" {
|
||||
factor = "`memo`.`visibility`"
|
||||
} else if identifier == "content" {
|
||||
factor = "`memo`.`content`"
|
||||
}
|
||||
if _, err := ctx.Buffer.WriteString(fmt.Sprintf("%s %s ?", factor, operator)); err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.Args = append(ctx.Args, valueStr)
|
||||
}
|
||||
case "@in":
|
||||
if len(v.CallExpr.Args) != 2 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue