Skip to content

Commit 603831e

Browse files
authored
fix: update tutorial Prisma (#1873)
1 parent bbcd135 commit 603831e

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

examples/tutorials/prisma.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,32 @@ cd rest-api-with-prisma-oak
3434
Then, let's run `prisma init` with Deno:
3535

3636
```shell
37-
deno run --allow-read --allow-env --allow-write npm:prisma@latest init
37+
npx prisma@latest init --generator-provider prisma-client --output ./generated
3838
```
3939

40+
Let's understand the key parameters:
41+
42+
- `--generator-provider prisma-client`: Define o provedor "prisma-client" ao
43+
invés do padrão "prisma-client-js". O provedor "prisma-client" é otimizado
44+
para Deno e gera código TypeScript compatível com o runtime do Deno.
45+
46+
- `--output`: Define o diretório onde o Prisma salvará os arquivos do cliente
47+
gerado, incluindo definições de tipos e utilitários de acesso ao banco de
48+
dados.
49+
4050
This will generate
41-
[`prisma/schema.prisma`](https://www.prisma.io/docs/concepts/components/prisma-schema).
42-
Let's update it with the following:
51+
[`prisma/schema.prisma`](https://www.prisma.io/docs/orm/prisma-schema). Let's
52+
update it with the following:
53+
54+
> [!TIP]
55+
> Don't forget to add `runtime = "deno"` to the generator block in your
56+
> schema.prisma file. This is required for Prisma to work correctly with Deno.
4357
4458
```ts
4559
generator client {
46-
provider = "prisma-client-js"
47-
previewFeatures = ["deno"]
48-
output = "../generated/client"
60+
provider = "prisma-client"
61+
output = "./generated"
62+
runtime = "deno"
4963
}
5064

5165
datasource db {
@@ -74,11 +88,14 @@ deno run -A npm:prisma@latest db push
7488
After that's complete, we'll need to generate a Prisma Client:
7589

7690
```shell
77-
deno run -A --unstable-detect-cjs npm:prisma@latest generate --no-engine
91+
deno run -A npm:prisma@latest generate
7892
```
7993

8094
## Setup Accelerate in the Prisma Data Platform
8195

96+
> Note: This is an optional step. Prisma Accelerate is not required for the
97+
> basic functionality.
98+
8299
To get started with the Prisma Data Platform:
83100

84101
1. Sign up for a free [Prisma Data Platform account](https://console.prisma.io).
@@ -103,10 +120,10 @@ touch prisma/seed.ts
103120
And in `./prisma/seed.ts`:
104121

105122
```ts
106-
import { Prisma, PrismaClient } from "../generated/client/deno/edge.ts";
123+
import { Prisma, PrismaClient } from "./generated/client.ts";
107124

108125
const prisma = new PrismaClient({
109-
datasourceUrl: envVars.DATABASE_URL,
126+
datasourceUrl: Deno.env.get("DATABASE_URL"),
110127
});
111128

112129
const dinosaurData: Prisma.DinosaurCreateInput[] = [
@@ -175,7 +192,7 @@ touch main.ts
175192
Then, in your `main.ts` file:
176193

177194
```ts
178-
import { PrismaClient } from "./generated/client/deno/edge.ts";
195+
import { PrismaClient } from "./prisma/generated/client.ts";
179196
import { Application, Router } from "jsr:@oak/oak";
180197

181198
/**
@@ -185,7 +202,7 @@ import { Application, Router } from "jsr:@oak/oak";
185202
const prisma = new PrismaClient({
186203
datasources: {
187204
db: {
188-
url: envVars.DATABASE_URL,
205+
url: Deno.env.get("DATABASE_URL")!,
189206
},
190207
},
191208
});
@@ -217,7 +234,7 @@ router
217234
})
218235
.post("/dinosaur", async (context) => {
219236
// Create a new dinosaur.
220-
const { name, description } = await context.request.body("json").value;
237+
const { name, description } = await context.request.body.json();
221238
const result = await prisma.dinosaur.create({
222239
data: {
223240
name,

0 commit comments

Comments
 (0)