-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
Finding by items in JsonType #1359
Comments
Currently the only way to do this is via embeddables in object mode, but we could support this for JSON columns too (as well as object properties in mongo). https://mikro-orm.io/docs/embeddables/#storing-embeddables-as-objects |
Ah okay I see, that makes sense. My main problem is that |
We can query by JSON object properties easily: ```ts const b = await em.findOne(Book, { meta: { valid: true, nested: { foo: '123', bar: 321, deep: { baz: 59, qux: false, }, }, }, }); ``` Will produce following query (in postgres): ```sql select "e0".* from "book" as "e0" where ("meta"->>'valid')::bool = true and "meta"->'nested'->>'foo' = '123' and ("meta"->'nested'->>'bar')::float8 = 321 and ("meta"->'nested'->'deep'->>'baz')::float8 = 59 and ("meta"->'nested'->'deep'->>'qux')::bool = false limit 1 ``` > All drivers are currently supported (including sqlite and mongo). In postgres we > also try to cast the value if we detect number or boolean on the right-hand side. Closes #1359 Related: #1261
We can query by JSON object properties easily: ```ts const b = await em.findOne(Book, { meta: { valid: true, nested: { foo: '123', bar: 321, deep: { baz: 59, qux: false, }, }, }, }); ``` Will produce following query (in postgres): ```sql select "e0".* from "book" as "e0" where ("meta"->>'valid')::bool = true and "meta"->'nested'->>'foo' = '123' and ("meta"->'nested'->>'bar')::float8 = 321 and ("meta"->'nested'->'deep'->>'baz')::float8 = 59 and ("meta"->'nested'->'deep'->>'qux')::bool = false limit 1 ``` > All drivers are currently supported (including sqlite and mongo). In postgres we > also try to cast the value if we detect number or boolean on the right-hand side. Closes #1359 Related: #1261
We can query by JSON object properties easily: ```ts const b = await em.findOne(Book, { meta: { valid: true, nested: { foo: '123', bar: 321, deep: { baz: 59, qux: false, }, }, }, }); ``` Will produce following query (in postgres): ```sql select "e0".* from "book" as "e0" where ("meta"->>'valid')::bool = true and "meta"->'nested'->>'foo' = '123' and ("meta"->'nested'->>'bar')::float8 = 321 and ("meta"->'nested'->'deep'->>'baz')::float8 = 59 and ("meta"->'nested'->'deep'->>'qux')::bool = false limit 1 ``` > All drivers are currently supported (including sqlite and mongo). In postgres we > also try to cast the value if we detect number or boolean on the right-hand side. Closes #1359 Related: #1261
We can query by JSON object properties easily: ```ts const b = await em.findOne(Book, { meta: { valid: true, nested: { foo: '123', bar: 321, deep: { baz: 59, qux: false, }, }, }, }); ``` Will produce following query (in postgres): ```sql select "e0".* from "book" as "e0" where ("meta"->>'valid')::bool = true and "meta"->'nested'->>'foo' = '123' and ("meta"->'nested'->>'bar')::float8 = 321 and ("meta"->'nested'->'deep'->>'baz')::float8 = 59 and ("meta"->'nested'->'deep'->>'qux')::bool = false limit 1 ``` > All drivers are currently supported (including sqlite and mongo). In postgres we > also try to cast the value if we detect number or boolean on the right-hand side. Closes #1359 Related: #1261
Thanks @B4nan ! |
Hey,
If you had a JsonType field that had this signature:
customProps: { [key: string]: any }
, is there a nice way to search for keys inside that object?Currently to find a player with the specified
customProps
key I'm doing:Ideally I'd do something like this:
However that throws an error with the query helper:
Am I missing something or is there currently no way of finding by items inside a json column?
The text was updated successfully, but these errors were encountered: