Skip to content

Commit 88316c8

Browse files
committed
Tweaking wording in e-com tutorial. Linking as
supplementary information.
1 parent ca35b8b commit 88316c8

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/content/docs/d1/best-practices/read-replication.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,5 @@ You may wish to refer to the following resources:
587587
- Blog: [Building D1: a Global Database](https://blog.cloudflare.com/building-d1-a-global-database/)
588588
- [D1 Sessions API documentation](/d1/worker-api/d1-database#withsession)
589589
- [Starter code for D1 Sessions API demo](https://github.com/cloudflare/templates/tree/staging/d1-starter-sessions-api)
590-
- [E-commerce store read replication demo](https://github.com/harshil1712/e-com-d1)
590+
- [E-commerce store read replication demo](https://github.com/harshil1712/e-com-d1)
591+
- [E-commerce store read replication tutorial](/d1/tutorials/using-read-replication-for-e-com)

src/content/docs/d1/tutorials/using-read-replication-for-e-com/index.mdx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
Details,
2121
} from "~/components";
2222

23-
[D1 Read Replication](/d1/features/read-replication/) is a feature that allows you to replicate your D1 database to multiple regions. This is useful for your e-commerce website, as it reduces read latencies and improves availability. In this tutorial, you will learn how to use D1 read replication for your e-commerce website.
23+
[D1 Read Replication](/d1/best-practices/read-replication/) is a feature that allows you to replicate your D1 database to multiple regions. This is useful for your e-commerce website, as it reduces read latencies and improves availability. In this tutorial, you will learn how to use D1 read replication for your e-commerce website.
2424

2525
While this tutorial uses a fictional e-commerce website, the principles can be applied to any use-case that requires high availability and low read latencies, such as a news website, a social media platform, or a marketing website.
2626

@@ -34,11 +34,7 @@ This will create a repository in your GitHub account and deploy the application
3434

3535
After deploying to Cloudflare through the button, this tutorial requires you to enable read replication for your newly created D1 database.
3636

37-
To enable D1 Read Replication for your database, run the following command:
38-
39-
```sh
40-
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/<accountid>/d1/database/<databaseId>" -H "Authorization: Bearer $TOKEN" -H "Content-Type:application/json" --data '{ "read_replication": { "mode": "auto" } }'
41-
```
37+
To enable D1 Read Replication for your database, follow the steps in [Enable read replication](/d1/best-practices/read-replication/#enable-read-replication).
4238

4339
## Prerequisites
4440

@@ -479,10 +475,10 @@ Add the D1 bindings returned in the terminal to the `wrangler` file:
479475

480476
<WranglerConfig>
481477
```toml
482-
[[d1_databases]]
478+
[[d1_databases]]
483479
binding = "DB"
484480
database_name = "fast-commerce"
485-
database_id = "YOUR_DATABASE_ID"
481+
database_id = "YOUR_DATABASE_ID"
486482
```
487483
</WranglerConfig>
488484

@@ -492,7 +488,7 @@ Run the following command to update the `Env` interface in the `worker-congifura
492488
npm run cf-typegen
493489
```
494490

495-
Next, enable read replication for the D1 database by running the following command. You will need to replace `<accountid>` with your Cloudflare account ID, `<databaseId>` with the ID of the D1 database, and `$TOKEN` with your Cloudflare API token. You can learn more about it in the [Read replication documentation](/d1/features/read-replication/#enable-read-replication).
491+
Next, enable read replication for the D1 database by running the following command. You will need to replace `<accountid>` with your Cloudflare account ID, `<databaseId>` with the ID of the D1 database, and `$TOKEN` with your Cloudflare API token. You can learn more about it in the [Read replication documentation](/d1/best-practices/read-replication/#enable-read-replication).
496492

497493
:::note
498494
Read replication is only used when the application has been [deployed](/d1/tutorials/using-read-replication-for-e-com/#step-8-deploy-the-application). D1 does not create read replicas when you develop locally. To test it locally, you can start the development server with the `--remote` flag.
@@ -572,7 +568,7 @@ Update the API routes to connect to the D1 database.
572568

573569
### 1. POST /api/product
574570

575-
```ts
571+
```ts
576572
app.post('/api/product', async (c) => {
577573
const product = await c.req.json();
578574

@@ -645,7 +641,7 @@ In the above code:
645641
- You then set the bookmark in the cookie.
646642
- Finally, you return the response.
647643

648-
Since you are writing the data to the database, you use the `first-primary` constraint. Even if you use the `first-unconstrained` constraint or pass a bookmark, the write request will always be routed to the primary database.
644+
Since you want to start the session with the latest data, you use the `first-primary` constraint. Even if you use the `first-unconstrained` constraint or pass a bookmark, the write request will always be routed to the primary database.
649645

650646
The bookmark set in the cookie can be used to get the data from the database for a new session from that instance.
651647

0 commit comments

Comments
 (0)