Here's what you need to do:
1- Install the generator
- Using npm
npm install prisma-class-validator-generator
- Using yarn:
yarn add prisma-class-validator-generator
2- Add the generator to your Prisma schema
generator class_validator { provider = "prisma-class-validator-generator" }
3- Run npx prisma generate
for your schema(or the example below)
model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] } model Post { id Int @id @default(autoincrement()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt title String content String? published Boolean @default(false) viewCount Int @default(0) author User? @relation(fields: [authorId], references: [id]) authorId Int? }
Now you will have all possible Class Validator models generated with their validations for you!
Top comments (0)