https://github.com/omar-dulaimi/prisma-custom-models-generator
Prisma 2+ generator to emit custom models from your schema"
https://github.com/omar-dulaimi/prisma-custom-models-generator
custom-models prisma prisma-generator
Last synced: 12 months ago
JSON representation
Prisma 2+ generator to emit custom models from your schema"
- Host: GitHub
- URL: https://github.com/omar-dulaimi/prisma-custom-models-generator
- Owner: omar-dulaimi
- License: mit
- Created: 2022-07-17T17:09:03.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-11T17:40:15.000Z (about 2 years ago)
- Last Synced: 2025-06-11T23:20:08.465Z (about 1 year ago)
- Topics: custom-models, prisma, prisma-generator
- Language: TypeScript
- Homepage:
- Size: 135 KB
- Stars: 21
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://badge.fury.io/js/prisma-custom-models-generator)
[](https://www.npmjs.com/package/prisma-custom-models-generator)
[](http://hits.dwyl.com/omar-dulaimi/prisma-custom-models-generator)
[](LICENSE)
Prisma Custom Models Generator
A Prisma generator that automates creating custom models from your Prisma schema.
Explore the options »
Report Bug
·
Request Feature
## Table of Contents
- [About The Project](#about-the-project)
- [Installation](#installation)
- [Usage](#usage)
- [Additional Options](#additional-options)
- [Community](#community)
# About The Project
Automatically generate custom models from your [Prisma](https://github.com/prisma/prisma) Schema. This includes all currently recommended ways as mentioned on [Prisma Docs](https://www.prisma.io/docs/concepts/components/prisma-client/custom-models). Updates every time `npx prisma generate` runs.
# Installation
Using npm:
```bash
npm install prisma-custom-models-generator
```
Using yarn:
```bash
yarn add prisma-custom-models-generator
```
# Usage
1- Star this repo 😉
2- Add the generator to your Prisma schema
```prisma
generator custom_models {
provider = "prisma-custom-models-generator"
behavior = "WRAP"
}
```
3- Running `npx prisma generate` for the following schema.prisma
```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(default behavior is `WRAP`)
```ts
import { PrismaClient } from '@prisma/client';
export function Users(prismaUser: PrismaClient['user']) {
return Object.assign(prismaUser, {
// define methods here, comma-separated
});
}
```
or this
```ts
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`
```prisma
generator custom_models {
provider = "prisma-custom-models-generator"
behavior = "EXTEND"
}
```
# Community
[](https://github.com/omar-dulaimi/prisma-custom-models-generator/stargazers)