You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(feat) Removes Accelerate specific instructions for Prisma Postgres (#7268)
* (feat) Removes Accelerate specific instructions for Prisma Postgres
* feat: update Deno integration guide to include additional development dependencies
If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).
If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).
60
+
61
+
:::
62
+
56
63
## Step 2. Introspect your database
57
64
58
65
### 2.1. Set up Prisma ORM
@@ -252,15 +259,9 @@ model Todo {
252
259
}
253
260
```
254
261
255
-
## Step 3. Install and generate Prisma Client
256
-
257
-
As a next step, you can install Prisma Client in your project so that you can start replacing the database queries in your project that are currently made with Drizzle:
258
-
259
-
```terminal
260
-
npm install @prisma/client
261
-
```
262
+
## Step 3. Generate Prisma Client
262
263
263
-
After installing, you need to run `generate` in order to have your schema reflected in TypeScript types and autocomplete.
264
+
Now that you have installed Prisma Client in Step 1, you need to run `generate` in order to have your schema reflected in TypeScript types and autocomplete.
If using [Prisma Postgres](https://prisma.io/postgres), install the `@prisma/extension-accelerate` package:
124
-
125
-
<TabbedContentcodegroupId="packageManager">
126
-
<TabItemvalue="npm">
127
-
128
-
```terminal
129
-
npm install @prisma/extension-accelerate
130
-
```
131
-
132
-
</TabItem>
133
-
134
-
<TabItemvalue="yarn">
135
-
136
-
```terminal
137
-
yarn add @prisma/extension-accelerate
138
-
```
139
-
140
-
</TabItem>
141
-
142
-
<TabItemvalue="pnpm">
143
-
144
-
```terminal
145
-
pnpm add @prisma/extension-accelerate
146
-
```
121
+
:::info
147
122
148
-
</TabItem>
149
-
</TabbedContent>
123
+
If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).
150
124
151
125
:::
152
126
@@ -389,27 +363,6 @@ Next, export the generated types and an instance of `PrismaClient` so it can use
389
363
390
364
In the `packages/database` directory, create a `src` folder and add a `client.ts` file. This file will define an instance of `PrismaClient`:
391
365
392
-
<TabbedContent code>
393
-
<TabItem value="Prisma Postgres (recommended)">
394
-
395
-
```ts file=packages/database/src/client.ts
396
-
import { PrismaClient } from "../generated/prisma";
397
-
import { withAccelerate } from "@prisma/extension-accelerate";
398
-
399
-
const globalForPrisma = global as unknown as { prisma: PrismaClient };
400
-
401
-
export const prisma =
402
-
globalForPrisma.prisma || new PrismaClient({
403
-
accelerateUrl: process.env.DATABASE_URL,
404
-
}).$extends(withAccelerate());
405
-
406
-
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
407
-
```
408
-
409
-
</TabItem>
410
-
411
-
<TabItemvalue="Other databases">
412
-
413
366
```ts file=packages/database/src/client.ts
414
367
import { PrismaClient } from "../generated/prisma";
415
368
import { PrismaPg } from '@prisma/adapter-pg';
@@ -428,9 +381,6 @@ export const prisma =
428
381
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
429
382
```
430
383
431
-
</TabItem>
432
-
</TabbedContent>
433
-
434
384
Then create an `index.ts` file in the `src` folder to re-export the generated prisma types and the `PrismaClient` instance:
If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).
77
+
78
+
:::
83
79
84
80
Once installed, initialize Prisma in your project:
This file creates a Prisma Client and attaches it to the global object so that only one instance of the client is created in your application. This helps resolve issues with hot reloading that can occur when using Prisma ORM with Next.js in development mode.
339
310
@@ -707,9 +678,10 @@ Before you deploy, you also need to tell Vercel to make sure that the Prisma Cli
If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).
88
+
89
+
:::
90
+
85
91
### 1.3. Set up Prisma ORM
86
92
87
93
Now, initialize Prisma to generate the necessary files:
Copy file name to clipboardExpand all lines: content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx
+13-24Lines changed: 13 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,18 +93,13 @@ pnpm install
93
93
Then, add additional dependencies:
94
94
95
95
```terminal
96
-
pnpm add typescript tsx @types/node -D
97
-
```
98
-
99
-
Then install the Prisma Client extension required to use Prisma Postgres:
100
-
101
-
```terminal
102
-
pnpm add @prisma/extension-accelerate
96
+
pnpm add typescript tsx @types/node @types/pg -D
97
+
pnpm add @prisma/adapter-pg pg
103
98
```
104
99
105
100
:::info
106
101
107
-
This guide uses [Prisma Postgres](/postgres/getting-started). If you plan to use a different database, you can omit the [@prisma/extension-accelerate package](https://www.npmjs.com/package/@prisma/extension-accelerate/).
102
+
If you are using a different database provider (MySQL, SQL Server, SQLite), install the corresponding driver adapter package instead of `@prisma/adapter-pg`. For more information, see [Database drivers](/orm/overview/databases/database-drivers).
108
103
109
104
:::
110
105
@@ -215,40 +210,34 @@ pnpm run db:migrate
215
210
216
211
When prompted by the CLI, enter a descriptive name for your migration.
217
212
218
-
Once the migration is successful, create a `client.ts` file to initialize Prisma Client with the Accelerate extension:
213
+
Once the migration is successful, create a `client.ts` file to initialize Prisma Client with a driver adapter:
219
214
220
215
```ts file=database/client.ts
221
216
// add-start
222
217
import { PrismaClient } from "./generated/client";
223
-
import { withAccelerate } from "@prisma/extension-accelerate";
218
+
import { PrismaPg } from "@prisma/adapter-pg";
224
219
225
-
// Instantiate the extended Prisma client to infer its type
226
-
const extendedPrisma = new PrismaClient({
227
-
accelerateUrl: process.env.DATABASE_URL,
228
-
}).$extends(withAccelerate());
229
-
type ExtendedPrismaClient = typeof extendedPrisma;
220
+
const adapter = new PrismaPg({
221
+
connectionString: process.env.DATABASE_URL,
222
+
});
230
223
231
224
// Use globalThis for broader environment compatibility
232
225
const globalForPrisma = globalThis as typeof globalThis & {
233
-
prisma?: ExtendedPrismaClient;
226
+
prisma?: PrismaClient;
234
227
};
235
228
236
229
// Named export with global memoization
237
-
export const prisma: ExtendedPrismaClient =
238
-
globalForPrisma.prisma ?? extendedPrisma;
230
+
export const prisma: PrismaClient =
231
+
globalForPrisma.prisma ?? new PrismaClient({
232
+
adapter,
233
+
});
239
234
240
235
if (process.env.NODE_ENV !== "production") {
241
236
globalForPrisma.prisma = prisma;
242
237
}
243
238
// add-end
244
239
```
245
240
246
-
:::info
247
-
248
-
If you're not using [Prisma Postgres](/postgres/getting-started) for your database, exclude the `import { withAccelerate }` line and `.$extends(withAccelerate())` from the line following it.
249
-
250
-
:::
251
-
252
241
Then, create an `index.ts` file to re-export the instance of Prisma Client and all generated types:
0 commit comments