@@ -34,18 +34,32 @@ cd rest-api-with-prisma-oak
34
34
Then, let's run ` prisma init ` with Deno:
35
35
36
36
``` 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
38
38
```
39
39
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
+
40
50
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.
43
57
44
58
``` ts
45
59
generator client {
46
- provider = " prisma-client-js "
47
- previewFeatures = [ " deno " ]
48
- output = " ../generated/client "
60
+ provider = " prisma-client"
61
+ output = " ./generated "
62
+ runtime = " deno "
49
63
}
50
64
51
65
datasource db {
@@ -74,11 +88,14 @@ deno run -A npm:prisma@latest db push
74
88
After that's complete, we'll need to generate a Prisma Client:
75
89
76
90
``` shell
77
- deno run -A --unstable-detect-cjs npm:prisma@latest generate --no-engine
91
+ deno run -A npm:prisma@latest generate
78
92
```
79
93
80
94
## Setup Accelerate in the Prisma Data Platform
81
95
96
+ > Note: This is an optional step. Prisma Accelerate is not required for the
97
+ > basic functionality.
98
+
82
99
To get started with the Prisma Data Platform:
83
100
84
101
1 . Sign up for a free [ Prisma Data Platform account] ( https://console.prisma.io ) .
@@ -103,10 +120,10 @@ touch prisma/seed.ts
103
120
And in ` ./prisma/seed.ts ` :
104
121
105
122
``` ts
106
- import { Prisma , PrismaClient } from " .. /generated/client/deno/edge .ts" ;
123
+ import { Prisma , PrismaClient } from " ./generated/client.ts" ;
107
124
108
125
const prisma = new PrismaClient ({
109
- datasourceUrl: envVars . DATABASE_URL ,
126
+ datasourceUrl: Deno . env . get ( " DATABASE_URL" ) ,
110
127
});
111
128
112
129
const dinosaurData: Prisma .DinosaurCreateInput [] = [
@@ -175,7 +192,7 @@ touch main.ts
175
192
Then, in your ` main.ts ` file:
176
193
177
194
``` ts
178
- import { PrismaClient } from " ./generated/client/deno/edge .ts" ;
195
+ import { PrismaClient } from " ./prisma/ generated/client.ts" ;
179
196
import { Application , Router } from " jsr:@oak/oak" ;
180
197
181
198
/**
@@ -185,7 +202,7 @@ import { Application, Router } from "jsr:@oak/oak";
185
202
const prisma = new PrismaClient ({
186
203
datasources: {
187
204
db: {
188
- url: envVars . DATABASE_URL ,
205
+ url: Deno . env . get ( " DATABASE_URL" ) ! ,
189
206
},
190
207
},
191
208
});
@@ -217,7 +234,7 @@ router
217
234
})
218
235
.post (" /dinosaur" , async (context ) => {
219
236
// Create a new dinosaur.
220
- const { name, description } = await context .request .body ( " json" ). value ;
237
+ const { name, description } = await context .request .body . json () ;
221
238
const result = await prisma .dinosaur .create ({
222
239
data: {
223
240
name ,
0 commit comments