prisma-custom-models-generator
v0.1.0
Published
Prisma 2+ generator to emit custom models from your schema
Downloads
546
Maintainers
Readme
Table of Contents
About The Project
Automatically generate custom models from your Prisma Schema. This includes all currently recommended ways as mentioned on Prisma Docs. Updates every time npx prisma generate
runs.
Installation
Using npm:
npm install prisma-custom-models-generator
Using yarn:
yarn add prisma-custom-models-generator
Usage
1- Star this repo 😉
2- Add the generator to your Prisma schema
generator custom_models {
provider = "prisma-custom-models-generator"
behavior = "WRAP"
}
3- Running npx prisma generate
for the following schema.prisma
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?
}
will generate this for the User model
import { PrismaClient } from '@prisma/client';
export function Users(prismaUser: PrismaClient['user']) {
return Object.assign(prismaUser, {
// define methods here, comma-separated
});
}
or this
import { PrismaClient } from '@prisma/client';
export class Users {
constructor(private readonly prismaUser: PrismaClient['user']) {}
}
Additional Options
| Option | Description | Type | Default |
| ---------- | ---------------------------------------------------------- | ---------------- | ------------- |
| output
| Output directory for the generated routers and zod schemas | string
| ./generated
|
| behavior
| Sets the preferred grouping logic | WRAP Or EXTEND
| WRAP
|
Use additional options in the schema.prisma
generator custom_models {
provider = "prisma-custom-models-generator"
behavior = "EXTEND"
}