Skip to content

Commit 240e343

Browse files
docs: update the Prisma ORM page to use Prisma Postgres (#13299)
prisma updates
1 parent 0bcd32d commit 240e343

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

docs/pages/getting-started/adapters/prisma.mdx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,55 @@ import { Accordion, Accordions } from "@/components/Accordion"
1515
### Installation
1616

1717
```bash npm2yarn
18-
npm install @prisma/client @auth/prisma-adapter
18+
npm install @prisma/client @prisma/extension-accelerate @auth/prisma-adapter
1919
npm install prisma --save-dev
2020
```
2121

2222
### Environment Variables
2323

24-
Prisma needs to set up the environment variable to establish a connection with your database and retrieve data. Prisma requires the `DATABASE_URL` environment variable to create the connection. For more information, read the [docs](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/connect-your-database-typescript-postgresql).
24+
If you're using Prisma Postgres, the `DATABASE_URL` will be automatically set up during initialization. For other databases, you'll need to manually configure the `DATABASE_URL` environment variable. For more information, read the [docs](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/connect-your-database-typescript-postgresql).
2525

2626
```sh
2727
DATABASE_URL=postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=SCHEMA
2828
```
2929

3030
### Configuration
3131

32+
First, initialize Prisma in your project. If you're using Prisma Postgres, run:
33+
34+
```bash
35+
npx prisma init --db --output ./src/generated/prisma
36+
```
37+
38+
This will create a Prisma Postgres database, set up your schema file, and configure the output directory for the generated Prisma Client.
39+
40+
For other databases, run:
41+
42+
```bash
43+
npx prisma init --output ./src/generated/prisma
44+
```
45+
46+
Then manually configure your `DATABASE_URL` in the `.env` file.
47+
3248
To improve performance using `Prisma ORM`, we can set up the Prisma instance to ensure only one instance is created throughout the project and then import it from any file as needed. This approach avoids recreating instances of PrismaClient every time it is used. Finally, we can import the Prisma instance from the `auth.ts` file configuration.
3349

3450
```ts filename="prisma.ts"
35-
import { PrismaClient } from "@prisma/client"
51+
import { PrismaClient } from "../src/generated/client"
52+
import { withAccelerate } from "@prisma/extension-accelerate"
3653

3754
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }
3855

39-
export const prisma = globalForPrisma.prisma || new PrismaClient()
56+
export const prisma =
57+
globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate())
4058

4159
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma
4260
```
4361

62+
<Callout type="info">
63+
If you're not using Prisma Postgres with Accelerate, you can omit the
64+
`withAccelerate()` extension and delete `.$extends(withAccelerate())`.
65+
</Callout>
66+
4467
<Callout type="warning">
4568
We recommend using version `@prisma/[email protected]` or above if using
4669
middleware or any other edge runtime(s). See [edge
@@ -147,7 +170,8 @@ datasource db {
147170
}
148171
149172
generator client {
150-
provider = "prisma-client-js"
173+
provider = "prisma-client"
174+
output = "../src/generated/prisma"
151175
}
152176
153177
model User {
@@ -231,7 +255,8 @@ datasource db {
231255
}
232256
233257
generator client {
234-
provider = "prisma-client-js"
258+
provider = "prisma-client"
259+
output = "../src/generated/prisma"
235260
}
236261
237262
model User {
@@ -330,7 +355,8 @@ datasource db {
330355
}
331356
332357
generator client {
333-
provider = "prisma-client-js"
358+
provider = "prisma-client"
359+
output = "../src/generated/prisma"
334360
}
335361
336362
model User {
@@ -416,7 +442,8 @@ datasource db {
416442
}
417443
418444
generator client {
419-
provider = "prisma-client-js"
445+
provider = "prisma-client"
446+
output = "../src/generated/prisma"
420447
}
421448
422449
model User {

0 commit comments

Comments
 (0)