fix: pinned shortcut comparison operators (#4987)

This commit is contained in:
Neo 2025-08-10 15:22:54 +09:00 committed by GitHub
parent 9f8921d3b9
commit 6b507ff600
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 33 additions and 2 deletions

View File

@ -122,7 +122,7 @@ func (c *CommonSQLConverter) handleComparisonOperator(ctx *ConvertContext, callE
return err
}
if !slices.Contains([]string{"creator_id", "created_ts", "updated_ts", "visibility", "content", "has_task_list", "has_link", "has_code", "has_incomplete_tasks"}, identifier) {
if !slices.Contains([]string{"creator_id", "created_ts", "updated_ts", "visibility", "content", "pinned", "has_task_list", "has_link", "has_code", "has_incomplete_tasks"}, identifier) {
return errors.Errorf("invalid identifier for %s", callExpr.Function)
}
@ -140,6 +140,8 @@ func (c *CommonSQLConverter) handleComparisonOperator(ctx *ConvertContext, callE
return c.handleStringComparison(ctx, identifier, operator, value)
case "creator_id":
return c.handleIntComparison(ctx, identifier, operator, value)
case "pinned":
return c.handlePinnedComparison(ctx, operator, value)
case "has_task_list", "has_link", "has_code", "has_incomplete_tasks":
return c.handleBooleanComparison(ctx, identifier, operator, value)
}
@ -491,6 +493,35 @@ func (c *CommonSQLConverter) handleIntComparison(ctx *ConvertContext, field, ope
return nil
}
func (c *CommonSQLConverter) handlePinnedComparison(ctx *ConvertContext, operator string, value interface{}) error {
if operator != "=" && operator != "!=" {
return errors.Errorf("invalid operator for pinned field")
}
valueBool, ok := value.(bool)
if !ok {
return errors.New("invalid boolean value for pinned field")
}
tablePrefix := c.dialect.GetTablePrefix("memo")
var sqlExpr string
if _, ok := c.dialect.(*PostgreSQLDialect); ok {
sqlExpr = fmt.Sprintf("%s.pinned %s %s", tablePrefix, operator, c.dialect.GetParameterPlaceholder(c.paramIndex))
} else {
sqlExpr = fmt.Sprintf("%s.`pinned` %s %s", tablePrefix, operator, c.dialect.GetParameterPlaceholder(c.paramIndex))
}
if _, err := ctx.Buffer.WriteString(sqlExpr); err != nil {
return err
}
ctx.Args = append(ctx.Args, c.dialect.GetBooleanValue(valueBool))
c.paramIndex++
return nil
}
func (c *CommonSQLConverter) handleBooleanComparison(ctx *ConvertContext, field, operator string, value interface{}) error {
if operator != "=" && operator != "!=" {
return errors.Errorf("invalid operator for %s", field)
@ -574,7 +605,7 @@ func (c *CommonSQLConverter) handleBooleanComparison(ctx *ConvertContext, field,
// Handle PostgreSQL differently - it uses the raw operator
if _, ok := c.dialect.(*PostgreSQLDialect); ok {
var jsonExtract = c.dialect.GetJSONExtract(jsonPath)
jsonExtract := c.dialect.GetJSONExtract(jsonPath)
sqlExpr := fmt.Sprintf("(%s)::boolean %s %s",
jsonExtract,