CarterGrimmeisen / zod-prisma

A custom prisma generator that creates Zod schemas from your Prisma model.
MIT License
817 stars 85 forks source link

Nullability and JSON fields #79

Open CarterGrimmeisen opened 2 years ago

CarterGrimmeisen commented 2 years ago

According to Prisma's docs JSON fields cannot be directly set to null. Instead one can utilize Prisma.JsonNull or Prisma.DbNull in order to set the field to a JSON value of null or to NULL the db field respectively.

My current plan is to update the generated zod schemas to match this behavior but I am curious as to what others think about this.

zomars commented 2 years ago

The only issue that I see with this approach is using these schemas to validate forms in the frontend. We could use null on the frontend and add a transform that converts it to Prisma.JsonNull or Prisma.DbNull