Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON contains #4

Closed
aclowkey opened this issue Jul 3, 2020 · 1 comment
Closed

JSON contains #4

aclowkey opened this issue Jul 3, 2020 · 1 comment

Comments

@aclowkey
Copy link

aclowkey commented Jul 3, 2020

Describe the feature

It would be nice to have an abillity to filter by the values of the json, and not just check their key presence

Something like

datatypes.JSONContains("json_column").Path("$.labels.my_label").Value("my_value")

Which would be SQL in MySQL

SELECT * FROM my_table WHERE JSON_CONTAINS("json_column", '"my_value',  "$.labels.my_label")

Not sure how it would be in Postgres

Motivation

As we might want to give users ability to filter based on specific json values from a set of attributes

@aclowkey aclowkey changed the title JSON Equals JSON contains Jul 6, 2020
@jinzhu
Copy link
Member

jinzhu commented Jul 9, 2020

// Check JSON extract value from keys equal to value
datatypes.JSONQuery("attributes").Equals(value, keys...)

DB.First(&user, datatypes.JSONQuery("attributes").Equals("jinzhu", "name"))
DB.First(&user, datatypes.JSONQuery("attributes").Equals("orgb", "orgs", "orgb"))

@jinzhu jinzhu closed this as completed Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants