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

Filter on JSON attribute's values content? #279

Open
ghost opened this issue Sep 27, 2019 · 4 comments
Open

Filter on JSON attribute's values content? #279

ghost opened this issue Sep 27, 2019 · 4 comments

Comments

@ghost
Copy link

ghost commented Sep 27, 2019

Is it possible to filter on an attribute value embedded in the value of a JSON attribute when using TypeORM with Postgres? Consider this json -- 'attrs' is an attribute of item that has JSON content with fields name and status.

{
    "id": 2,
    "name": "Item #2",
    "attrs": {
        "name": "Item #2",
        "status": "rejected"
    }
}

I would like to find all items were the status value is rejected.
Note: The JSON of the attrs column is highly variable from instance to instance.

@michaelyali
Copy link
Member

michaelyali commented Sep 30, 2019

no, I believe it's not possible to filter embedded fields.
nevertheless, we have this PR #267 and I need to test it including filtering those columns

@ghost
Copy link
Author

ghost commented Oct 1, 2019

I was able to eventually figure this out -- basically needs a query with a "Where" clause that goes something like this (NOTE: This is Postgres specific), --

WHERE 'attrs' ::jsonb ->> 'status' = 'rejected'

Using this approach, I have been able to make progress. It seems like it should definitely be possible to adapt the nestjsx/crud to support such complexity although from a design perspective I see that the query criteria on a request could get rather complicated.

Thoughts?

@Diluka
Copy link
Contributor

Diluka commented Oct 11, 2019

there are some concepts #149 #150

@mattsidjohn
Copy link

Any update on this @zMotivat0r ?

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

3 participants