mirror of https://github.com/usememos/memos.git
fix: tests
This commit is contained in:
parent
b55904a428
commit
e24f92b719
|
|
@ -184,7 +184,7 @@ func (d *DB) convertWithTemplates(ctx *filter.ConvertContext, expr *exprv1.Expr)
|
|||
if !ok {
|
||||
return errors.Errorf("invalid boolean value for %s", identifier)
|
||||
}
|
||||
|
||||
|
||||
// Map identifier to JSON path
|
||||
var jsonPath string
|
||||
switch identifier {
|
||||
|
|
@ -195,7 +195,7 @@ func (d *DB) convertWithTemplates(ctx *filter.ConvertContext, expr *exprv1.Expr)
|
|||
case "has_incomplete_tasks":
|
||||
jsonPath = "$.property.hasIncompleteTasks"
|
||||
}
|
||||
|
||||
|
||||
// Use JSON_EXTRACT for boolean comparison like has_task_list
|
||||
var sqlTemplate string
|
||||
if operator == "=" {
|
||||
|
|
@ -323,7 +323,7 @@ func (d *DB) convertWithTemplates(ctx *filter.ConvertContext, expr *exprv1.Expr)
|
|||
return err
|
||||
}
|
||||
} else if identifier == "has_code" {
|
||||
// Handle has_code as a standalone boolean identifier
|
||||
// Handle has_code as a standalone boolean identifier
|
||||
if _, err := ctx.Buffer.WriteString("JSON_EXTRACT(`memo`.`payload`, '$.property.hasCode') = CAST('true' AS JSON)"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ func (d *DB) convertWithParameterIndex(ctx *filter.ConvertContext, expr *exprv1.
|
|||
if !ok {
|
||||
return paramIndex, errors.Errorf("invalid boolean value for %s", identifier)
|
||||
}
|
||||
|
||||
|
||||
// Map identifier to JSON path
|
||||
var jsonPath string
|
||||
switch identifier {
|
||||
|
|
@ -203,22 +203,14 @@ func (d *DB) convertWithParameterIndex(ctx *filter.ConvertContext, expr *exprv1.
|
|||
case "has_incomplete_tasks":
|
||||
jsonPath = "$.property.hasIncompleteTasks"
|
||||
}
|
||||
|
||||
|
||||
// Use JSON path for boolean comparison with PostgreSQL parameter placeholder
|
||||
placeholder := filter.GetParameterPlaceholder(dbType, paramIndex)
|
||||
var sqlTemplate string
|
||||
if operator == "=" {
|
||||
if valueBool {
|
||||
sqlTemplate = fmt.Sprintf("(%s->'payload'->'property'->>'%s')::boolean = %s", filter.GetSQL("table_prefix", dbType), strings.TrimPrefix(jsonPath, "$.property."), placeholder)
|
||||
} else {
|
||||
sqlTemplate = fmt.Sprintf("(%s->'payload'->'property'->>'%s')::boolean = %s", filter.GetSQL("table_prefix", dbType), strings.TrimPrefix(jsonPath, "$.property."), placeholder)
|
||||
}
|
||||
sqlTemplate = fmt.Sprintf("(%s->'payload'->'property'->>'%s')::boolean = %s", filter.GetSQL("table_prefix", dbType), strings.TrimPrefix(jsonPath, "$.property."), placeholder)
|
||||
} else { // operator == "!="
|
||||
if valueBool {
|
||||
sqlTemplate = fmt.Sprintf("(%s->'payload'->'property'->>'%s')::boolean != %s", filter.GetSQL("table_prefix", dbType), strings.TrimPrefix(jsonPath, "$.property."), placeholder)
|
||||
} else {
|
||||
sqlTemplate = fmt.Sprintf("(%s->'payload'->'property'->>'%s')::boolean != %s", filter.GetSQL("table_prefix", dbType), strings.TrimPrefix(jsonPath, "$.property."), placeholder)
|
||||
}
|
||||
sqlTemplate = fmt.Sprintf("(%s->'payload'->'property'->>'%s')::boolean != %s", filter.GetSQL("table_prefix", dbType), strings.TrimPrefix(jsonPath, "$.property."), placeholder)
|
||||
}
|
||||
if _, err := ctx.Buffer.WriteString(sqlTemplate); err != nil {
|
||||
return paramIndex, err
|
||||
|
|
@ -347,7 +339,7 @@ func (d *DB) convertWithParameterIndex(ctx *filter.ConvertContext, expr *exprv1.
|
|||
return paramIndex, err
|
||||
}
|
||||
} else if identifier == "has_code" {
|
||||
// Handle has_code as a standalone boolean identifier
|
||||
// Handle has_code as a standalone boolean identifier
|
||||
if _, err := ctx.Buffer.WriteString(fmt.Sprintf("(%s->'payload'->'property'->>'hasCode')::boolean = true", filter.GetSQL("table_prefix", dbType))); err != nil {
|
||||
return paramIndex, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ func (d *DB) convertWithTemplates(ctx *filter.ConvertContext, expr *exprv1.Expr)
|
|||
if !ok {
|
||||
return errors.Errorf("invalid boolean value for %s", identifier)
|
||||
}
|
||||
|
||||
|
||||
// Map identifier to JSON path
|
||||
var jsonPath string
|
||||
switch identifier {
|
||||
|
|
@ -195,7 +195,7 @@ func (d *DB) convertWithTemplates(ctx *filter.ConvertContext, expr *exprv1.Expr)
|
|||
case "has_incomplete_tasks":
|
||||
jsonPath = "$.property.hasIncompleteTasks"
|
||||
}
|
||||
|
||||
|
||||
// Use JSON_EXTRACT for boolean comparison like has_task_list
|
||||
var sqlTemplate string
|
||||
if operator == "=" {
|
||||
|
|
@ -323,7 +323,7 @@ func (d *DB) convertWithTemplates(ctx *filter.ConvertContext, expr *exprv1.Expr)
|
|||
return err
|
||||
}
|
||||
} else if identifier == "has_code" {
|
||||
// Handle has_code as a standalone boolean identifier
|
||||
// Handle has_code as a standalone boolean identifier
|
||||
if _, err := ctx.Buffer.WriteString("JSON_EXTRACT(`memo`.`payload`, '$.property.hasCode') = JSON('true')"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue