Skip to content

Commit d773abf

Browse files
Oxyjunpedrosousa
andauthored
Apply suggestions from code review part 1
Co-authored-by: Pedro Sousa <[email protected]>
1 parent 86ab52c commit d773abf

File tree

1 file changed

+8
-15
lines changed
  • src/content/docs/d1/tutorials/d1-and-orange-orm

1 file changed

+8
-15
lines changed

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ Open your terminal, and run the following command to create a Cloudflare Worker
5353
cd orange-d1-example
5454
```
5555

56-
```sh frame="none"
57-
cd orange-d1-example
58-
```
59-
6056
### 2. Install Orange ORM
6157

6258
:::note
@@ -66,11 +62,9 @@ D1 is supported in Orange ORM as of [v4.5.0](https://github.com/alfateam/orange-
6662
:::
6763

6864
```sh
69-
cd orange-d1-example
7065
npm install orange-orm
7166
```
7267

73-
You can create a D1 database via the [Cloudflare dashboard](https://dash.cloudflare.com), or via `wrangler`. This tutorial uses the `wrangler` CLI.
7468

7569
### 3. Create your D1 database
7670

@@ -84,7 +78,7 @@ npx wrangler d1 create orange-demo-db
8478

8579
You should receive the following output on your terminal:
8680

87-
```sh
81+
```txt
8882
✅ Successfully created DB 'orange-demo-db' in region EEUR
8983
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
9084
point-in-time restore.
@@ -102,7 +96,7 @@ point-in-time restore.
10296

10397
You now have a D1 database in your Cloudflare account with a binding to your Cloudflare Worker.
10498

105-
Copy the `json` snippet from the command output and paste it into your `wrangler.jsonc` file. Your `wrangler.jsonc` file should look similar to the following:
99+
Copy the JSON snippet from the command output and paste it into your `wrangler.jsonc` file. Your `wrangler.jsonc` file should look similar to the following:
106100

107101
<WranglerConfig>
108102

@@ -127,15 +121,15 @@ Copy the `json` snippet from the command output and paste it into your `wrangler
127121

128122
</WranglerConfig>
129123

130-
`<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 orange-demo-db` in your terminal.
124+
Replace `<YOUR_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 orange-demo-db` in your terminal.
131125

132126
Next, create a database table in the database to send queries to D1 using Orange ORM.
133127

134128
### 4. Create a table in the database
135129

136-
D1 has a [migration system](/d1/reference/migrations), and in the following steps, you will use D1's migration system to create and run a migration against your database.
130+
D1 has a [migration system](/d1/reference/migrations/), and in the following steps, you will use D1's migration system to create and run a migration against your database.
137131

138-
1. First, create a new migration using `wrangler`:
132+
1. Create a new migration using `wrangler`:
139133

140134
```sh
141135
npx wrangler d1 migrations create orange-demo-db create_user_table
@@ -164,13 +158,12 @@ CREATE TABLE "User" (
164158
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
165159
```
166160

167-
168161
You now need to use the `wrangler d1 migrations apply` command to send this SQL statement to D1. This command accepts two flags:
169162

170163
- `--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.
171164
- `--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.
172165

173-
In this tutorial, you will first test the Worker locally, then deploy your Worker afterwards.
166+
In this tutorial, you will first test the Worker locally, then deploy your Worker.
174167

175168
4. Open your terminal, and run both commands:
176169

@@ -202,7 +195,7 @@ npx wrangler d1 execute orange-demo-db --command "INSERT INTO \"User\" (\"email
202195

203196
To query your database from the Worker using Orange ORM, you need to:
204197

205-
1. Create a `src/map.ts` with the following code:
198+
1. Create a `src/map.ts` file with the following code:
206199

207200
```ts
208201
import orange from 'orange-orm';
@@ -246,7 +239,7 @@ export default {
246239
npm run dev
247240
```
248241

249-
2. Open your browser at [`http://localhost:8787`](http://localhost:8787/) to check the result of the database query. You should see the following `json` block:
242+
2. Open your browser at [`http://localhost:8787`](http://localhost:8787/) to check the result of the database query. You should see the following JSON block:
250243

251244
```json
252245
[{ "id": 1, "email": "[email protected]", "name": "Jane Doe (Local)" }]

0 commit comments

Comments
 (0)