Less restrictive JSON types on create/insert #24054
Labels
bug/2-confirmed
Bug has been reproduced and confirmed.
kind/bug
A reported bug.
team/client
Issue for team Client.
topic: client types
Types in Prisma Client
topic: create()
topic: Json
Scalar type `Json`
Problem
When using the Prisma client (with Postgres in my case) to update data in the database, I've frequently been slowed down by the more restrictive types of the insert and create functions. For example, given the model
And attempting to insert data that follows the type
You are often met with a message like
Even though CustomData does satisfy the requirements for the JSON field (on retrieval/return I understand there is no guarantee of the structure, but on insert there should be a guarantee)
Suggested solution
If possible,
.insert
and.create
(along with the typesMyModelCreateWithout...
etc) should ideally be able to allow types that satisfy the requirements of the JSON field instead of strictly requiring that it matches every possible JSON type. While I understand this is likely a TypeScript limitation, potentially there could be investigation into alternative solutions?Alternatives
Potentially allow declaration and/or validation of JSON fields coming from the database (although this could contradict the goal of the Json field type).
Additional context
N/A
The text was updated successfully, but these errors were encountered: