From 597bccc080ad17478a14cb72768655573a80fa62 Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Mon, 6 May 2024 13:15:15 +0200 Subject: [PATCH] fix: add SQL JSON validity check to meta_data query --- internal/repository/query.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/repository/query.go b/internal/repository/query.go index 94aa742..5ca98fb 100644 --- a/internal/repository/query.go +++ b/internal/repository/query.go @@ -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 { + // 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 { return query.Where("JSON_EXTRACT(meta_data, \"$."+jsonField+"\") = ?", *cond.Eq) }