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
[D1] Prisma ORM D1 tutorial Deploy to Cloudflare button (#22859)
* Updating to use GitHubCode where possible.
* Adding Deploy to Cloudflare button.
* Catching typo
* Update src/content/docs/d1/tutorials/d1-and-prisma-orm/index.mdx
Co-authored-by: Maddy <[email protected]>
---------
Co-authored-by: Maddy <[email protected]>
@@ -21,14 +21,24 @@ To learn more about Prisma ORM, refer to the [Prisma documentation](https://www.
21
21
22
22
## Query D1 from a Cloudflare Worker using Prisma ORM
23
23
24
-
This example shows you how to set up and deploy a Cloudflare Worker that is accessing a D1 database from scratch.
24
+
This tutorial shows you how to set up and deploy a Cloudflare Worker that is accessing a D1 database from scratch.
25
25
26
-
### Prerequisites
26
+
## Quick start
27
+
28
+
If you want to skip the steps and get started quickly, select **Deploy to Cloudflare** below.
29
+
30
+
[](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/d1-prisma/d1/query-d1-using-prisma)
31
+
32
+
This creates a repository in your GitHub account and deploys the application to Cloudflare Workers. Use this option if you are familiar with Cloudflare Workers, and wish to skip the step-by-step guidance.
33
+
34
+
You may wish to manually follow the steps if you are new to Cloudflare Workers.
35
+
36
+
## Prerequisites
27
37
28
38
-[`Node.js`](https://nodejs.org/en/) and [`npm`](https://docs.npmjs.com/getting-started) installed on your machine.
29
39
- A [Cloudflare account](https://dash.cloudflare.com).
30
40
31
-
###1. Create a Cloudflare Worker
41
+
## 1. Create a Cloudflare Worker
32
42
33
43
Open your terminal, and run the following command to create a Cloudflare Worker using Cloudflare's [`hello-world`](https://github.com/cloudflare/workers-sdk/tree/4fdd8987772d914cf50725e9fa8cb91a82a6870d/packages/create-cloudflare/templates/hello-world) template:
34
44
@@ -41,7 +51,7 @@ In your terminal, you will be asked a series of questions related your project:
41
51
1. Answer `yes` to using TypeScript.
42
52
2. Answer `no` to deploying your Worker.
43
53
44
-
###2. Initialize Prisma ORM
54
+
## 2. Initialize Prisma ORM
45
55
46
56
:::note
47
57
@@ -80,15 +90,15 @@ Since you will use the [driver adapter](https://www.prisma.io/docs/orm/overview/
80
90
81
91
Open your `schema.prisma` file and adjust the `generator` block to reflect as follows:
82
92
83
-
```diff
93
+
```prisma title="schema.prisma"
84
94
generator client {
85
95
provider = "prisma-client-js"
86
96
output = "../src/generated/prisma"
87
97
previewFeatures = ["driverAdapters"]
88
98
}
89
99
```
90
100
91
-
###3. Create your D1 database
101
+
## 3. Create your D1 database
92
102
93
103
In this step, you will set up your D1 database. You can create a D1 database via the [Cloudflare dashboard](https://dash.cloudflare.com), or via `wrangler`. This tutorial will use the `wrangler` CLI.
94
104
@@ -141,7 +151,7 @@ Replace `<D1_DATABASE_ID>` with the database ID of your D1 instance. If you were
141
151
142
152
Next, you will create a database table in the database to send queries to D1 using Prisma ORM.
143
153
144
-
###4. Create a table in the database
154
+
## 4. Create a table in the database
145
155
146
156
[Prisma Migrate](https://www.prisma.io/docs/orm/prisma-migrate/understanding-prisma-migrate/overview) does not support D1 yet, so you cannot follow the default migration workflows using `prisma migrate dev` or `prisma db push`.
147
157
@@ -151,7 +161,7 @@ Prisma Migrate for D1 is currently in Early Access. If you want to try it out, y
151
161
152
162
:::
153
163
154
-
D1 uses [migrations](/d1/reference/migrations) for managing schema changes, and the Prisma CLI can help generate the necessary SQL for those updates. In the steps below, you'll use both tools to create and apply a migration to your database.
164
+
D1 uses [migrations](/d1/reference/migrations) for managing schema changes, and the Prisma CLI can help generate the necessary SQL for those updates. In the steps below, you will use both tools to create and apply a migration to your database.
155
165
156
166
First, create a new migration using `wrangler`:
157
167
@@ -175,13 +185,16 @@ Next, you need to add the SQL statement that will create a `User` table to that
175
185
176
186
Open the `schema.prisma` file and add the following `User` model to your schema:
`UNIQUE INDEX` on `email` was created because the `User` model in your Prisma schema is using the [`@unique`](https://www.prisma.io/docs/orm/reference/prisma-schema-reference#unique) attribute on its `email` field.
0 commit comments