Skip to content

Commit 58be6c7

Browse files
committed
docs(): update for new release
1 parent c83fa74 commit 58be6c7

File tree

2 files changed

+108
-26
lines changed

2 files changed

+108
-26
lines changed

content/200-orm/500-reference/325-prisma-config-reference.mdx

Lines changed: 99 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ You can define your config in either of two ways:
1414
- Using the `defineConfig` helper:
1515
```ts
1616
import path from "node:path";
17-
import { defineConfig } from "prisma/config";
17+
import { defineConfig, env } from "prisma/config";
1818

1919
export default defineConfig({
2020
schema: path.join("prisma", "schema.prisma"),
21-
migrations: {
21+
migrations: {
2222
path: path.join("db", "migrations"),
2323
},
24-
views: {
24+
views: {
2525
path: path.join("db", "views"),
2626
},
27-
typedSql: {
28-
path: path.join("db", "queries"),
27+
typedSql: {
28+
path: path.join("db", "queries"),
29+
},
30+
engine: "classic",
31+
datasource: {
32+
url: env("DATABASE_URL")
2933
}
3034
});
3135
```
@@ -45,6 +49,10 @@ You can define your config in either of two ways:
4549
},
4650
typedSql: {
4751
path: path.join("db", "queries"),
52+
},
53+
engine: "classic",
54+
datasource: {
55+
url: env("DATABASE_URL")
4856
}
4957
} satisfies PrismaConfig;
5058
```
@@ -90,6 +98,8 @@ export declare type PrismaConfig = {
9098
typedSql?: {
9199
path: string;
92100
};
101+
// Depending on the choice, you must provide either a `datasource` object or driver adapter
102+
engine: 'classic': 'js'
93103

94104
};
95105
```
@@ -131,9 +141,6 @@ import path from "node:path";
131141
import type { PrismaConfig } from "prisma";
132142
import { PrismaD1 } from "@prisma/adapter-d1";
133143

134-
// import your .env file
135-
import "dotenv/config";
136-
137144
export default {
138145
experimental: {
139146
adapter: true
@@ -332,6 +339,55 @@ Failed to load config file "~" as a TypeScript/JavaScript module. Error: Error:
332339

333340
:::
334341

342+
343+
### `engine`
344+
345+
Configure the schema engine your project should use.
346+
347+
| Property | Type | Required | Default |
348+
| -------- | ------------------ | -------- | ----------------- |
349+
| `engine` | `classic` or `js` | No | `classic` |
350+
351+
By default it is set to use the Rust-based schema engine, which requires that `datasource` be set
352+
in your `prisma.config.ts`.
353+
354+
```ts
355+
import path from "node:path";
356+
import { defineConfig, env } from "@prisma/config";
357+
export default defineConfig({
358+
engine: "classic",
359+
datasource: {
360+
url: env('DATABASE_URL'),
361+
},
362+
schema: path.join("prisma", "schema.prisma"),
363+
});
364+
```
365+
366+
Alternatively, if you are opting to use the newer Rust-free schema engine, set the engine to `js` and
367+
provide the adapter you wish to use
368+
369+
```ts
370+
import path from "node:path";
371+
import { defineConfig, env } from "@prisma/config";
372+
import { PrismaD1 } from "@prisma/adapter-d1";
373+
export default defineConfig({
374+
experimental: {
375+
adapter: true
376+
},
377+
engine: "js",
378+
async adapter() {
379+
return new PrismaD1({
380+
CLOUDFLARE_D1_TOKEN: process.env.CLOUDFLARE_D1_TOKEN,
381+
CLOUDFLARE_ACCOUNT_ID: process.env.CLOUDFLARE_ACCOUNT_ID,
382+
CLOUDFLARE_DATABASE_ID: process.env.CLOUDFLARE_DATABASE_ID,
383+
});
384+
},
385+
schema: path.join("prisma", "schema.prisma"),
386+
});
387+
388+
```
389+
390+
335391
## Common patterns
336392

337393
### Setting up your project
@@ -356,27 +412,37 @@ export default {} satisfies PrismaConfig;
356412

357413
### Using environment variables
358414

359-
When using `prisma.config.ts`, environment variables from `.env` files are not automatically loaded. If you're using node or deno, you'll need to:
415+
When using `prisma.config.ts`, environment variables from `.env` files are not automatically loaded. Using `tsx`, you can pass a `--env-file` flag and that will automatically add those values to `process.env`
360416

361-
1. Pass a `--env-file` flag to the command line
417+
If using Node or Deno:
362418

363-
<TabbedContent code>
364-
<TabItem value="Node">
365419
```terminal
366-
node --env-file=.env index.js
367-
node --env-file=.env --env-file=.local.env index.js
420+
tsx --env-file=.env src/index.ts
421+
tsx watch --env-file=.env --env-file=.local.env src/index.ts
422+
tsx --env-file=.env ./prisma/seed.ts
368423
```
369-
</TabItem>
370-
<TabItem value="Deno">
371-
```terminal
372-
deno run --env-file main.ts
373-
deno run --env-file=.env --env-file=.local.env main.ts
374-
```
375-
</TabItem>
376-
</TabbedContent>
377424

378425
For Bun, `.env` files are automatically loaded.
379426

427+
For accessing environment variables within `prisma.config.ts`, use the `env()` helper function to
428+
provide a type-safe way of accessing that variable:
429+
430+
```tsx
431+
import path from "node:path";
432+
import { defineConfig, env } from "@prisma/config";
433+
434+
type Env = {
435+
DATABASE_URL: string
436+
}
437+
export default defineConfig({
438+
engine: "classic",
439+
datasource: {
440+
url: env<Env>('DATABASE_URL'),
441+
},
442+
schema: path.join("prisma", "schema.prisma"),
443+
});
444+
```
445+
380446
For releases of Node before v20, you'll need to:
381447

382448
1. Install the `dotenv` package:
@@ -389,11 +455,18 @@ npm install dotenv
389455

390456
```ts
391457
import "dotenv/config";
392-
import type { PrismaConfig } from "prisma";
458+
import { defineConfig, env } from "@prisma/config";
393459

394-
export default {
395-
// now you can use process.env variables
396-
} satisfies PrismaConfig;
460+
type Env = {
461+
DATABASE_URL: string
462+
}
463+
export default defineConfig({
464+
engine: "classic",
465+
datasource: {
466+
url: env<Env>('DATABASE_URL'),
467+
},
468+
schema: path.join("prisma", "schema.prisma"),
469+
});
397470
```
398471

399472
### Using multi-file schemas

content/250-postgres/100-introduction/250-overview.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ You can view the following usage metrics in your Console Dashboard:
2727
- Cumulative operations
2828
- Operations per day
2929

30+
For details into individual databases in your workspace, each database has it's own metrics report
31+
as well. You can view the following:
32+
33+
- Average response size
34+
- Average query duration
35+
- Total egress
36+
- Total Operations
37+
- Cache utilisation
38+
3039
## Billing
3140

3241
### Usage-based pricing

0 commit comments

Comments
 (0)