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-specific filtering #2444

Closed
tomhoule opened this issue May 14, 2020 · 9 comments · Fixed by prisma/prisma-engines#1872
Closed

JSON-specific filtering #2444

tomhoule opened this issue May 14, 2020 · 9 comments · Fixed by prisma/prisma-engines#1872
Assignees
Labels
kind/feature A request for a new feature. team/client Issue for team Client. topic: client types Types in Prisma Client topic: Json Scalar type `Json`
Milestone

Comments

@tomhoule
Copy link
Contributor

Problem

When working with Json fields, some databases (like postgres) let you manipulate the JSON value. This is useful for filtering, for example if you want to filter a model with a Json field where one object field (or a specific path) inside the json column matches a provided value. There are other operations like "object contains", "path exists", etc. that would be useful.

Additional context

This issue is the prolongation of #2345 - which is about simple filtering by Json field by equality, treating it as a scalar.

@janpio janpio added kind/feature A request for a new feature. topic: Json Scalar type `Json` labels May 14, 2020
@janpio janpio changed the title Feature: JSON-specific filtering JSON-specific filtering May 14, 2020
@luxaritas
Copy link
Contributor

luxaritas commented Jul 15, 2020

Few notes:

  • Django is shipping JSONField support to all DBs in 3.1, which includes full document querying - might be worthwhile taking a peek at what they've done
  • If I understand correctly, you should be able to perform any typical filtering operation on a JSON value - ie in a where clause, you could verify myjson.some.value > 5
  • At least in Postgres (though I assume in other engines), you can also index on individual keys

Would also just like to mention that as I'm evaluating Prisma as a possibility for our future backend rewrite, this is quite important for us. We have data that is not really viable to store relationally, but still needs to be queryable - and in some cases that dataset could be quite large. If it's helpful at any point, I'm happy to describe more about our use cases for this

@luxaritas
Copy link
Contributor

Another thought - it might be nice to have built-in support, or at least a recommended approach, for validating a JSON schema when updating a JSON field

@JoniBR
Copy link

JoniBR commented Sep 13, 2020

This feature would be really helpful! For example, we have a column integrations on our User table which holds a JSON with some external ids. A lot of times we need to filter the users by having a certain key inside that JSON.

@tre-dev
Copy link

tre-dev commented Dec 11, 2020

Can this please get pushed on the priority list? 🙏

@tradical-allstripes
Copy link

+1

This feature would be immensely helpful for me and my team

@michael-land
Copy link

really want this feature

@kladnik
Copy link

kladnik commented Apr 29, 2021

This is really needed and also PostgreSQL supports this naturally with queries. Can we get this soon?

@dpetrick
Copy link
Contributor

This is finished and released in 2.23, integration is done.

@matthewmueller
Copy link
Contributor

matthewmueller commented Jun 1, 2021

JSON Filtering Documentation is also up: https://www.prisma.io/docs/concepts/components/prisma-client/working-with-fields/working-with-json-fields

If you run into anything, let us know in #7135!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. topic: client types Types in Prisma Client topic: Json Scalar type `Json`
Projects
None yet
Development

Successfully merging a pull request may close this issue.