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
Copy file name to clipboardExpand all lines: src/content/docs/d1/tutorials/using-read-replication-for-e-com/index.mdx
+7-11Lines changed: 7 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ import {
20
20
Details,
21
21
} from"~/components";
22
22
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.
24
24
25
25
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.
26
26
@@ -34,11 +34,7 @@ This will create a repository in your GitHub account and deploy the application
34
34
35
35
After deploying to Cloudflare through the button, this tutorial requires you to enable read replication for your newly created D1 database.
36
36
37
-
To enable D1 Read Replication for your database, run the following command:
To enable D1 Read Replication for your database, follow the steps in [Enable read replication](/d1/best-practices/read-replication/#enable-read-replication).
42
38
43
39
## Prerequisites
44
40
@@ -479,10 +475,10 @@ Add the D1 bindings returned in the terminal to the `wrangler` file:
479
475
480
476
<WranglerConfig>
481
477
```toml
482
-
[[d1_databases]]
478
+
[[d1_databases]]
483
479
binding = "DB"
484
480
database_name = "fast-commerce"
485
-
database_id = "YOUR_DATABASE_ID"
481
+
database_id = "YOUR_DATABASE_ID"
486
482
```
487
483
</WranglerConfig>
488
484
@@ -492,7 +488,7 @@ Run the following command to update the `Env` interface in the `worker-congifura
492
488
npm run cf-typegen
493
489
```
494
490
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).
496
492
497
493
:::note
498
494
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.
572
568
573
569
### 1. POST /api/product
574
570
575
-
```ts
571
+
```ts
576
572
app.post('/api/product', async (c) => {
577
573
const product =awaitc.req.json();
578
574
@@ -645,7 +641,7 @@ In the above code:
645
641
- You then set the bookmark in the cookie.
646
642
- Finally, you return the response.
647
643
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.
649
645
650
646
The bookmark set in the cookie can be used to get the data from the database for a new session from that instance.
0 commit comments