fix: boolean filters (#4966)
This commit is contained in:
parent
66b4f583a5
commit
8319516d1a
4 changed files with 7 additions and 39 deletions
|
|
@ -550,23 +550,7 @@ func (c *CommonSQLConverter) handleBooleanComparison(ctx *ConvertContext, field,
|
||||||
|
|
||||||
// Handle PostgreSQL differently - it uses the raw operator
|
// Handle PostgreSQL differently - it uses the raw operator
|
||||||
if _, ok := c.dialect.(*PostgreSQLDialect); ok {
|
if _, ok := c.dialect.(*PostgreSQLDialect); ok {
|
||||||
var jsonExtract string
|
var jsonExtract = c.dialect.GetJSONExtract(jsonPath)
|
||||||
// Special handling for has_link, has_code, has_incomplete_tasks
|
|
||||||
if field == "has_link" || field == "has_code" || field == "has_incomplete_tasks" {
|
|
||||||
// Use memo-> format for these fields
|
|
||||||
parts := strings.Split(strings.TrimPrefix(jsonPath, "$."), ".")
|
|
||||||
jsonExtract = "memo->'payload'"
|
|
||||||
for i, part := range parts {
|
|
||||||
if i == len(parts)-1 {
|
|
||||||
jsonExtract += fmt.Sprintf("->>'%s'", part)
|
|
||||||
} else {
|
|
||||||
jsonExtract += fmt.Sprintf("->'%s'", part)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Use standard format for has_task_list
|
|
||||||
jsonExtract = c.dialect.GetJSONExtract(jsonPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlExpr := fmt.Sprintf("(%s)::boolean %s %s",
|
sqlExpr := fmt.Sprintf("(%s)::boolean %s %s",
|
||||||
jsonExtract,
|
jsonExtract,
|
||||||
|
|
|
||||||
|
|
@ -203,21 +203,6 @@ func (d *PostgreSQLDialect) GetBooleanComparison(path string, _ bool) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *PostgreSQLDialect) GetBooleanCheck(path string) string {
|
func (d *PostgreSQLDialect) GetBooleanCheck(path string) string {
|
||||||
// Special handling for standalone boolean identifiers
|
|
||||||
if strings.Contains(path, "hasLink") || strings.Contains(path, "hasCode") || strings.Contains(path, "hasIncompleteTasks") {
|
|
||||||
// Use memo-> instead of memo.payload-> for these fields
|
|
||||||
parts := strings.Split(strings.TrimPrefix(path, "$."), ".")
|
|
||||||
result := fmt.Sprintf("%s->'payload'", d.GetTablePrefix())
|
|
||||||
for i, part := range parts {
|
|
||||||
if i == len(parts)-1 {
|
|
||||||
result += fmt.Sprintf("->>'%s'", part)
|
|
||||||
} else {
|
|
||||||
result += fmt.Sprintf("->'%s'", part)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("(%s)::boolean = true", result)
|
|
||||||
}
|
|
||||||
// Use default format for other fields
|
|
||||||
return fmt.Sprintf("(%s)::boolean IS TRUE", d.GetJSONExtract(path))
|
return fmt.Sprintf("(%s)::boolean IS TRUE", d.GetJSONExtract(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,32 +117,32 @@ func TestConvertExprToSQL(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `has_link == true`,
|
filter: `has_link == true`,
|
||||||
want: "(memo->'payload'->'property'->>'hasLink')::boolean = $1",
|
want: "(memo.payload->'property'->>'hasLink')::boolean = $1",
|
||||||
args: []any{true},
|
args: []any{true},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `has_code == false`,
|
filter: `has_code == false`,
|
||||||
want: "(memo->'payload'->'property'->>'hasCode')::boolean = $1",
|
want: "(memo.payload->'property'->>'hasCode')::boolean = $1",
|
||||||
args: []any{false},
|
args: []any{false},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `has_incomplete_tasks != false`,
|
filter: `has_incomplete_tasks != false`,
|
||||||
want: "(memo->'payload'->'property'->>'hasIncompleteTasks')::boolean != $1",
|
want: "(memo.payload->'property'->>'hasIncompleteTasks')::boolean != $1",
|
||||||
args: []any{false},
|
args: []any{false},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `has_link`,
|
filter: `has_link`,
|
||||||
want: "(memo->'payload'->'property'->>'hasLink')::boolean = true",
|
want: "(memo.payload->'property'->>'hasLink')::boolean IS TRUE",
|
||||||
args: []any{},
|
args: []any{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `has_code`,
|
filter: `has_code`,
|
||||||
want: "(memo->'payload'->'property'->>'hasCode')::boolean = true",
|
want: "(memo.payload->'property'->>'hasCode')::boolean IS TRUE",
|
||||||
args: []any{},
|
args: []any{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
filter: `has_incomplete_tasks`,
|
filter: `has_incomplete_tasks`,
|
||||||
want: "(memo->'payload'->'property'->>'hasIncompleteTasks')::boolean = true",
|
want: "(memo.payload->'property'->>'hasIncompleteTasks')::boolean IS TRUE",
|
||||||
args: []any{},
|
args: []any{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ const Home = observer(() => {
|
||||||
conditions.push(`${factor} >= ${timestampAfter} && ${factor} < ${timestampAfter + 60 * 60 * 24}`);
|
conditions.push(`${factor} >= ${timestampAfter} && ${factor} < ${timestampAfter + 60 * 60 * 24}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("conditions", conditions);
|
|
||||||
return conditions.length > 0 ? conditions.join(" && ") : undefined;
|
return conditions.length > 0 ? conditions.join(" && ") : undefined;
|
||||||
}, [memoFilterStore.filters, selectedShortcut?.filter]);
|
}, [memoFilterStore.filters, selectedShortcut?.filter]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue