Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
4d6042e3
Unverified
Commit
4d6042e3
authored
Aug 03, 2025
by
Maximilian Krauß
Committed by
GitHub
Aug 03, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(tags): ensure JSON array elements are properly formatted in SQL queries (#4944)
parent
9c60165b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
13 deletions
+13
-13
common_converter.go
plugin/filter/common_converter.go
+1
-1
dialect.go
plugin/filter/dialect.go
+2
-2
memo_filter_test.go
store/db/mysql/memo_filter_test.go
+3
-3
memo_filter_test.go
store/db/postgres/memo_filter_test.go
+7
-7
No files found.
plugin/filter/common_converter.go
View file @
4d6042e3
...
...
@@ -266,7 +266,7 @@ func (c *CommonSQLConverter) handleTagInList(ctx *ConvertContext, values []any)
template
:=
c
.
dialect
.
GetJSONContains
(
"$.tags"
,
"element"
)
sql
:=
strings
.
Replace
(
template
,
"?"
,
c
.
dialect
.
GetParameterPlaceholder
(
c
.
paramIndex
),
1
)
subconditions
=
append
(
subconditions
,
sql
)
args
=
append
(
args
,
v
)
args
=
append
(
args
,
fmt
.
Sprintf
(
`"%s"`
,
v
)
)
}
c
.
paramIndex
++
}
...
...
plugin/filter/dialect.go
View file @
4d6042e3
...
...
@@ -185,12 +185,12 @@ func (d *PostgreSQLDialect) GetJSONArrayLength(path string) string {
func
(
d
*
PostgreSQLDialect
)
GetJSONContains
(
path
,
_
string
)
string
{
jsonPath
:=
strings
.
Replace
(
path
,
"$.tags"
,
"payload->'tags'"
,
1
)
return
fmt
.
Sprintf
(
"%s.%s @> jsonb_build_array(?)"
,
d
.
GetTablePrefix
(),
jsonPath
)
return
fmt
.
Sprintf
(
"%s.%s @> jsonb_build_array(?
::json
)"
,
d
.
GetTablePrefix
(),
jsonPath
)
}
func
(
d
*
PostgreSQLDialect
)
GetJSONLike
(
path
,
_
string
)
string
{
jsonPath
:=
strings
.
Replace
(
path
,
"$.tags"
,
"payload->'tags'"
,
1
)
return
fmt
.
Sprintf
(
"%s.%s @> jsonb_build_array(?)"
,
d
.
GetTablePrefix
(),
jsonPath
)
return
fmt
.
Sprintf
(
"%s.%s @> jsonb_build_array(?
::json
)"
,
d
.
GetTablePrefix
(),
jsonPath
)
}
func
(
*
PostgreSQLDialect
)
GetBooleanValue
(
value
bool
)
interface
{}
{
...
...
store/db/mysql/memo_filter_test.go
View file @
4d6042e3
...
...
@@ -18,12 +18,12 @@ func TestConvertExprToSQL(t *testing.T) {
{
filter
:
`tag in ["tag1", "tag2"]`
,
want
:
"(JSON_CONTAINS(JSON_EXTRACT(`memo`.`payload`, '$.tags'), ?) OR JSON_CONTAINS(JSON_EXTRACT(`memo`.`payload`, '$.tags'), ?))"
,
args
:
[]
any
{
"tag1"
,
"tag2"
},
args
:
[]
any
{
`"tag1"`
,
`"tag2"`
},
},
{
filter
:
`!(tag in ["tag1", "tag2"])`
,
want
:
"NOT ((JSON_CONTAINS(JSON_EXTRACT(`memo`.`payload`, '$.tags'), ?) OR JSON_CONTAINS(JSON_EXTRACT(`memo`.`payload`, '$.tags'), ?)))"
,
args
:
[]
any
{
"tag1"
,
"tag2"
},
args
:
[]
any
{
`"tag1"`
,
`"tag2"`
},
},
{
filter
:
`content.contains("memos")`
,
...
...
@@ -43,7 +43,7 @@ func TestConvertExprToSQL(t *testing.T) {
{
filter
:
`tag in ['tag1'] || content.contains('hello')`
,
want
:
"(JSON_CONTAINS(JSON_EXTRACT(`memo`.`payload`, '$.tags'), ?) OR `memo`.`content` LIKE ?)"
,
args
:
[]
any
{
"tag1"
,
"%hello%"
},
args
:
[]
any
{
`"tag1"`
,
"%hello%"
},
},
{
filter
:
`1`
,
...
...
store/db/postgres/memo_filter_test.go
View file @
4d6042e3
...
...
@@ -17,13 +17,13 @@ func TestConvertExprToSQL(t *testing.T) {
}{
{
filter
:
`tag in ["tag1", "tag2"]`
,
want
:
"(memo.payload->'tags' @> jsonb_build_array($1
) OR memo.payload->'tags' @> jsonb_build_array($2
))"
,
args
:
[]
any
{
"tag1"
,
"tag2"
},
want
:
"(memo.payload->'tags' @> jsonb_build_array($1
::json) OR memo.payload->'tags' @> jsonb_build_array($2::json
))"
,
args
:
[]
any
{
`"tag1"`
,
`"tag2"`
},
},
{
filter
:
`!(tag in ["tag1", "tag2"])`
,
want
:
"NOT ((memo.payload->'tags' @> jsonb_build_array($1
) OR memo.payload->'tags' @> jsonb_build_array($2
)))"
,
args
:
[]
any
{
"tag1"
,
"tag2"
},
want
:
"NOT ((memo.payload->'tags' @> jsonb_build_array($1
::json) OR memo.payload->'tags' @> jsonb_build_array($2::json
)))"
,
args
:
[]
any
{
`"tag1"`
,
`"tag2"`
},
},
{
filter
:
`content.contains("memos")`
,
...
...
@@ -42,8 +42,8 @@ func TestConvertExprToSQL(t *testing.T) {
},
{
filter
:
`tag in ['tag1'] || content.contains('hello')`
,
want
:
"(memo.payload->'tags' @> jsonb_build_array($1) OR memo.content ILIKE $2)"
,
args
:
[]
any
{
"tag1"
,
"%hello%"
},
want
:
"(memo.payload->'tags' @> jsonb_build_array($1
::json
) OR memo.content ILIKE $2)"
,
args
:
[]
any
{
`"tag1"`
,
"%hello%"
},
},
{
filter
:
`1`
,
...
...
@@ -107,7 +107,7 @@ func TestConvertExprToSQL(t *testing.T) {
},
{
filter
:
`"work" in tags`
,
want
:
"memo.payload->'tags' @> jsonb_build_array($1)"
,
want
:
"memo.payload->'tags' @> jsonb_build_array($1
::json
)"
,
args
:
[]
any
{
"work"
},
},
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment