Skip to content

Commit e12396d

Browse files
committed
Updating the tutorial with more details
1 parent 50cd3b1 commit e12396d

File tree

1 file changed

+20
-10
lines changed
  • src/content/docs/d1/tutorials/d1-and-prisma-orm

1 file changed

+20
-10
lines changed

src/content/docs/d1/tutorials/d1-and-prisma-orm/index.mdx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
updated: 2024-03-27
2+
updated: 2025-05-16
33
difficulty: Beginner
44
content_type: Tutorial
55
pcx_content_type: tutorial
@@ -11,7 +11,7 @@ languages:
1111
- SQL
1212
---
1313

14-
import { WranglerConfig } from "~/components";
14+
import { WranglerConfig, FileTree } from "~/components";
1515

1616
## What is Prisma ORM?
1717

@@ -86,6 +86,9 @@ generator client {
8686
+ previewFeatures = ["driverAdapters"]
8787
}
8888
```
89+
:::note
90+
Do not specify an `output` destination in the `generator client` block. Instead, allow prisma to generate the files in the default output path.
91+
:::
8992

9093
### 3. Create your D1 database
9194

@@ -108,7 +111,7 @@ Created your new D1 database.
108111
{
109112
"binding": "DB",
110113
"database_name": "prisma-demo-db",
111-
"database_id": "<DATABASE_ID>"
114+
"database_id": "<D1_DATABASE_ID>"
112115
}
113116
]
114117
}
@@ -129,12 +132,12 @@ compatibility_flags = ["nodejs_compat"]
129132
[[d1_databases]]
130133
binding = "DB" # i.e. available in your Worker on env.DB
131134
database_name = "prisma-demo-db"
132-
database_id = "__YOUR_D1_DATABASE_ID__"
135+
database_id = "<D1_DATABASE_ID>"
133136
```
134137

135138
</WranglerConfig>
136139

137-
`__YOUR_D1_DATABASE_ID__` should be replaced with the database ID of your D1 instance. If you were not able to fetch this ID from the terminal output, you can also find it in the [Cloudflare dashboard](https://dash.cloudflare.com/), or by running `npx wrangler d1 info prisma-demo-db` in your terminal.
140+
Replace `<D1_DATABASE_ID>` with the database ID of your D1 instance. If you were not able to fetch this ID from the terminal output, you can also find it in the [Cloudflare dashboard](https://dash.cloudflare.com/), or by running `npx wrangler d1 info prisma-demo-db` in your terminal.
138141

139142
Next, you will create a database table in the database to send queries to D1 using Prisma ORM.
140143

@@ -154,10 +157,11 @@ Answer `yes` to creating a new folder called `migrations`.
154157

155158
The command has now created a new directory called `migrations` and an empty file called `0001_create_user_table.sql` inside of it:
156159

157-
```
158-
migrations/
159-
└── 0001_create_user_table.sql
160-
```
160+
<FileTree>
161+
- prisma-d1-example
162+
- migrations
163+
- **0001_create_user_table.sql**
164+
</FileTree>
161165

162166
Next, you need to add the SQL statement that will create a `User` table to that file.
163167

@@ -198,7 +202,9 @@ You now need to use the `wrangler d1 migrations apply` command to send this SQL
198202
- `--local`: Executes the statement against a _local_ version of D1. This local version of D1 is a SQLite database file that will be located in the `.wrangler/state` directory of your project. Use this approach when you want to develop and test your Worker on your local machine. Refer to [Local development](/d1/best-practices/local-development/) to learn more.
199203
- `--remote`: Executes the statement against your _remote_ version of D1. This version is used by your _deployed_ Cloudflare Workers. Refer to [Remote development](/d1/best-practices/remote-development/) to learn more.
200204

201-
In this tutorial, you will do local and remote development. You will test the Worker locally and deploy your Worker afterwards. Open your terminal, and run both commands:
205+
In this tutorial, you will do both local and remote development. You will test the Worker locally, then deploy your Worker afterwards.
206+
207+
Open your terminal, and run both commands:
202208

203209
```sh
204210
# For the local database
@@ -226,6 +232,10 @@ npx wrangler d1 execute prisma-demo-db --command "INSERT INTO \"User\" (\"email
226232
('[email protected]', 'Jane Doe (Remote)');" --remote
227233
```
228234

235+
:::note
236+
If you receive an error to the effect of `Unknown arguments: (\email\,, \name\)...`, you may need to escape the double quotes with backticks (`) instead of backslashes (\\).
237+
:::
238+
229239
### 5. Query your database from the Worker
230240

231241
To query your database from the Worker using Prisma ORM, you need to:

0 commit comments

Comments
 (0)