RobertCraigie / prisma-client-py

Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
https://prisma-client-py.readthedocs.io
Apache License 2.0
1.89k stars 81 forks source link

Add support for filtering by Json values #64

Open RobertCraigie opened 3 years ago

RobertCraigie commented 3 years ago

Problem

Prisma supports filtering by the values of json fields, we should support it too.

Suggested solution

As the syntax for json filtering differs between database connectors, we should either create a wrapper that normalizes values or leave it up to the user like prisma does.

user = await client.user.find_first(
  where={
    'pets': {
      'path': JsonPath('favourite', 'breed'),
      'equals': 'Parson Russell Terrier',
    },
  },
)

PostgreSQL

user = await client.user.find_first(
  where={
    'pets': {
      'path': ['favourite', 'breed'],
      'equals': 'Parson Russell Terrier',
    },
  },
)

MySQL

user = await client.user.find_first(
  where={
    'pets': {
      'path': '$.favourite.breed',
      'equals': 'Parson Russell Terrier',
    },
  },
)

Additional context

full json filter reference working with json fields MySQL syntax PostgreSQL json

RobertCraigie commented 2 years ago

This is no longer a candidate due to: https://github.com/prisma/prisma-engines/issues/2435

We need to implement #99 before supporting this so that we can raise a runtime error ourselves when an invalid type is detected.

I do not want the user to be able to easily crash the query engine.