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
In your terminal, you will be asked a series of questions related your project:
40
40
41
41
1. Answer `yes` to using TypeScript.
42
-
2. Answer `yes` to deploying your Worker.
43
-
44
-
Once you deploy your Worker, you should be able to preview your Worker at `https://prisma-d1-example.USERNAME.workers.dev`, which displays "Hello World" in the browser.
42
+
2. Answer `no` to deploying your Worker.
45
43
46
44
### 2. Initialize Prisma ORM
47
45
@@ -88,6 +86,9 @@ generator client {
88
86
+ previewFeatures = ["driverAdapters"]
89
87
}
90
88
```
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.
You should receive the following output on your terminal:
103
104
104
105
```
105
-
✅ Successfully created DB 'prisma-demo-db' in region EEUR
106
-
Created your database using D1's new storage backend. The new storage backend is not yet recommended for production workloads, but backs up your data via
107
-
point-in-time restore.
108
-
109
-
[[d1_databases]]
110
-
binding = "DB" # i.e. available in your Worker on env.DB
111
-
database_name = "prisma-demo-db"
112
-
database_id = "__YOUR_D1_DATABASE_ID__"
106
+
✅ Successfully created DB 'prisma-demo-db' in region WEUR
107
+
Created your new D1 database.
108
+
109
+
{
110
+
"d1_databases": [
111
+
{
112
+
"binding": "DB",
113
+
"database_name": "prisma-demo-db",
114
+
"database_id": "<D1_DATABASE_ID>"
115
+
}
116
+
]
117
+
}
113
118
```
114
119
115
120
You now have a D1 database in your Cloudflare account with a binding to your Cloudflare Worker.
binding = "DB"# i.e. available in your Worker on env.DB
129
134
database_name = "prisma-demo-db"
130
-
database_id = "__YOUR_D1_DATABASE_ID__"
135
+
database_id = "<D1_DATABASE_ID>"
131
136
```
132
137
133
138
</WranglerConfig>
134
139
135
-
`__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.
136
141
137
142
Next, you will create a database table in the database to send queries to D1 using Prisma ORM.
138
143
@@ -152,10 +157,11 @@ Answer `yes` to creating a new folder called `migrations`.
152
157
153
158
The command has now created a new directory called `migrations` and an empty file called `0001_create_user_table.sql` inside of it:
154
159
155
-
```
156
-
migrations/
157
-
└── 0001_create_user_table.sql
158
-
```
160
+
<FileTree>
161
+
- prisma-d1-example
162
+
- migrations
163
+
-**0001_create_user_table.sql**
164
+
</FileTree>
159
165
160
166
Next, you need to add the SQL statement that will create a `User` table to that file.
161
167
@@ -196,7 +202,9 @@ You now need to use the `wrangler d1 migrations apply` command to send this SQL
196
202
-`--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.
197
203
-`--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.
198
204
199
-
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.
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 (\\).
0 commit comments