TypeScript issue with JSON[] field filter using path
I have the following model and am using a PostgreSQL database:
model Message { mentions Json[] }I am using
prisma-json-types-generator
to generate the types. For the mentions
field, the generator produced a type NullableListFilter
that does not have the path method.
When trying to filter on message
with a path using prisma.message.findMany
, I am getting the TypeScript error: Object literal may only specify known properties, and 'path' does not exist in type 'NullableListFilter<PrismaJson.Message>'.
Any thoughts on this issue are appreciated.6 Replies
You decided to hold for human wisdom. We'll chime in soon! Meanwhile,
#ask-ai
is there if you need a quick second opinion.hi @RaphaelEtim any thoughts on this issue?
Hi @sitaram
The NullableListFilter type generated by prisma-json-types-generator doesn't include the path method because Prisma doesn't support direct filtering on JSON arrays in PostgreSQL in the same way it does for single JSON fields. You may want to consider using raw SQL queries to perform the filtering if it's crucial to do it at the database level.
Thanks @RaphaelEtim for the response.
Does the single
Json
field support saving array of objects & filtering with path?Prisma supports filtering on Json fields using the path option, but the functionality differs between database connectors:
For MySQL, you can filter on object key values inside arrays. The Json filters documentation provides an example:
For PostgreSQL, filtering on object key values in arrays is not supported.
You can filter on the presence of a specific value in a scalar array (strings, integers). https://www.prisma.io/docs/orm/prisma-client/special-fields-and-types/working-with-json-fields#filtering-on-nested-array-value
Working with Json fields (Concepts) | Prisma Documentation
How to read, write, and filter by Json fields.