Skip to content

Commit 8d194c1

Browse files
Merge pull request #3298 from cookieMonsterDev/cookieMonsterDev/prisma-recipe
docs(prisma-recipe): update docs for Prisma client output path and build config
2 parents 4ceaf2f + 2c52513 commit 8d194c1

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

content/recipes/prisma.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ This command creates a new `prisma` directory with the following contents:
6767
- `schema.prisma`: Specifies your database connection and contains the database schema
6868
- `.env`: A [dotenv](https://github.com/motdotla/dotenv) file, typically used to store your database credentials in a group of environment variables
6969

70+
#### Set the generator output path
71+
72+
> warning **Warning** In Prisma ORM 7, Prisma Client will no longer be generated in `node_modules` by default and will require an output path to be defined. [Learn more below on how to define an output path](https://www.prisma.io/docs/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path).
73+
74+
Specify your output `path` for the generated Prisma client either by passing `--output ../generated/prisma` during prisma init, or directly in your Prisma schema:
75+
76+
```groovy
77+
generator client {
78+
provider = "prisma-client-js"
79+
output = "../generated/prisma"
80+
}
81+
```
82+
83+
By default, Nest does not include the generated Prisma client in the build. To fix this, the path should be explicitly defined in `tsconfig.build.json`:
84+
85+
```json
86+
{
87+
"extends": "./tsconfig.json",
88+
"include": ["src", "generated"],
89+
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
90+
}
91+
```
92+
7093
#### Set the database connection
7194

7295
Your database connection is configured in the `datasource` block in your `schema.prisma` file. By default it's set to `postgresql`, but since you're using a SQLite database in this guide you need to adjust the `provider` field of the `datasource` block to `sqlite`:
@@ -79,6 +102,7 @@ datasource db {
79102
80103
generator client {
81104
provider = "prisma-client-js"
105+
output = "../generated/prisma"
82106
}
83107
```
84108

@@ -110,6 +134,7 @@ datasource db {
110134
111135
generator client {
112136
provider = "prisma-client-js"
137+
output = "../generated/prisma"
113138
}
114139
```
115140

@@ -141,6 +166,7 @@ datasource db {
141166
142167
generator client {
143168
provider = "prisma-client-js"
169+
output = "../generated/prisma"
144170
}
145171
```
146172

@@ -166,6 +192,7 @@ datasource db {
166192
167193
generator client {
168194
provider = "prisma-client-js"
195+
output = "../generated/prisma"
169196
}
170197
```
171198

@@ -274,7 +301,7 @@ Inside the `src` directory, create a new file called `prisma.service.ts` and add
274301

275302
```typescript
276303
import { Injectable, OnModuleInit } from '@nestjs/common';
277-
import { PrismaClient } from '@prisma/client';
304+
import { PrismaClient } from 'generated/prisma';
278305

279306
@Injectable()
280307
export class PrismaService extends PrismaClient implements OnModuleInit {
@@ -293,7 +320,7 @@ Still inside the `src` directory, create a new file called `user.service.ts` and
293320
```typescript
294321
import { Injectable } from '@nestjs/common';
295322
import { PrismaService } from './prisma.service';
296-
import { User, Prisma } from '@prisma/client';
323+
import { User, Prisma } from 'generated/prisma';
297324

298325
@Injectable()
299326
export class UsersService {
@@ -358,7 +385,7 @@ Still inside the `src` directory, create a new file called `post.service.ts` and
358385
```typescript
359386
import { Injectable } from '@nestjs/common';
360387
import { PrismaService } from './prisma.service';
361-
import { Post, Prisma } from '@prisma/client';
388+
import { Post, Prisma } from 'generated/prisma';
362389

363390
@Injectable()
364391
export class PostsService {
@@ -436,7 +463,7 @@ import {
436463
} from '@nestjs/common';
437464
import { UsersService } from './user.service';
438465
import { PostsService } from './post.service';
439-
import { User as UserModel, Post as PostModel } from '@prisma/client';
466+
import { User as UserModel, Post as PostModel } from 'generated/prisma';
440467

441468
@Controller()
442469
export class AppController {

0 commit comments

Comments
 (0)