chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
578 stars 43 forks source link

Support native database filed types #214

Open RobertCZ opened 7 months ago

RobertCZ commented 7 months ago

Not sure if this is already possible and I just missed it in the docs but how about supporting database specific field types?

Eg Prisma already generates for MS SQL field TinyInt

UseFee Int @db.TinyInt

It would be nice to say somewhere that Int @db.TinyInt should be mapped to tinyint() and generate automatically

UseFee: tinyint()

for Zod with some db specific validators eg const tinyint = () => z.number().int().min(0).max(255)

chrishoermann commented 7 months ago

@RobertCZ thanks for the request but sadly this is not possbile yet, because these field types are currently not present in the prisma.dmmf which is the source of truth for all generated prisma types and also our generated schemas. 😢

RobertCZ commented 7 months ago

Thank you. Created question https://github.com/prisma/prisma/issues/22157

AlexanderArvidsson commented 4 months ago

@chrishoermann I proposed a workaround in the Prisma issue that I've been using in my own custom generator that might interest you: https://github.com/prisma/prisma/issues/10252#issuecomment-1962758703

Perhaps you can make use of the same method to generate better Zod schemas!