Skip to content

Commit

Permalink
feat: add comma separation for json fields in rs search
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Jan 24, 2025
1 parent b074373 commit f4dc518
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion query/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ var JSONPathMapper = func(ctx context.Context, tx *gorm.DB, column string, op ty
if !slices.Contains([]types.QueryOperator{types.Eq, types.Neq}, op) {
op = types.Eq
}
return tx.Where(fmt.Sprintf(`TRIM(BOTH '"' from jsonb_path_query_first(%s, '$.%s')::TEXT) %s ?`, column, path, op), val)
values := strings.Split(val, ",")
for _, v := range values {
tx = tx.Where(fmt.Sprintf(`TRIM(BOTH '"' from jsonb_path_query_first(%s, '$.%s')::TEXT) %s ?`, column, path, op), v)
}
return tx
}

var CommonFields = map[string]func(ctx context.Context, tx *gorm.DB, val string) (*gorm.DB, error){
Expand Down
6 changes: 6 additions & 0 deletions tests/query_resource_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ var _ = ginkgo.Describe("Resoure Selector with PEG", ginkgo.Ordered, func() {
expectedIDs: []uuid.UUID{dummy.KubernetesCluster.ID, dummy.EC2InstanceA.ID},
resource: "config",
},
{
description: "config labels multiple with ,",
query: `labels.account=flanksource labels.environment!=production,development`,
expectedIDs: []uuid.UUID{dummy.EC2InstanceA.ID},
resource: "config",
},
{
description: "config array query",
query: `config.spec.template.spec.containers[0].name=logistics-api`,
Expand Down

0 comments on commit f4dc518

Please sign in to comment.