mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-26 13:29:05 +01:00
fix: add SQL JSON validity check to meta_data query
This commit is contained in:
parent
72557fd0bf
commit
597bccc080
@ -236,6 +236,9 @@ func buildStringCondition(field string, cond *model.StringInput, query sq.Select
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildMetaJsonCondition(jsonField string, cond *model.StringInput, query sq.SelectBuilder) sq.SelectBuilder {
|
func buildMetaJsonCondition(jsonField string, cond *model.StringInput, query sq.SelectBuilder) sq.SelectBuilder {
|
||||||
|
// Verify and Search Only in Valid Jsons
|
||||||
|
query = query.Where("JSON_VALID(meta_data)")
|
||||||
|
// add "AND" Sql query Block for field match
|
||||||
if cond.Eq != nil {
|
if cond.Eq != nil {
|
||||||
return query.Where("JSON_EXTRACT(meta_data, \"$."+jsonField+"\") = ?", *cond.Eq)
|
return query.Where("JSON_EXTRACT(meta_data, \"$."+jsonField+"\") = ?", *cond.Eq)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user