Skip to content

Commit 487d1fd

Browse files
committed
add deploy to workers button
1 parent 719be48 commit 487d1fd

File tree

1 file changed

+17
-3
lines changed
  • src/content/docs/d1/tutorials/using-read-replication-for-e-com

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ import {
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

27+
## Quick start
28+
29+
If you want to skip the steps and get started quickly, click on the below button:
30+
31+
[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/harshil1712/e-com-d1-hono)
32+
33+
This will create a repository in your GitHub account and deploy the application to Cloudflare Workers. It will also create and bind a D1 database, create the required tables, and add some sample data. You can visit the deployed application. However, you need to enable D1 Read Replication for your database.
34+
35+
To enable D1 Read Replication for your database, run the following command:
36+
37+
```sh
38+
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" } }'
39+
```
40+
2741
## Prerequisites
2842

2943
<Render file="prereqs" product="workers" />
@@ -483,7 +497,7 @@ Read replication is only used when the application has been [deployed](/d1/tutor
483497
:::
484498

485499
```sh
486-
fetch -X PUT "https://api.cloudflare.com/client/v4/accounts/<accountid>/d1/database/<databaseId>" \
500+
curl -X PUT "https://api.cloudflare.com/client/v4/accounts/<accountid>/d1/database/<databaseId>" \
487501
-H "Authorization: Bearer $TOKEN" \
488502
-H "Content-Type:application/json" --data '{ "read_replication": { "mode": "auto" } }'
489503
```
@@ -629,9 +643,9 @@ In the above code:
629643
- You then set the bookmark in the cookie.
630644
- Finally, you return the response.
631645

632-
Since you are writing the data to the database, you use the `first-primary` constraint.
646+
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.
633647

634-
The bookmark set in the cookie is used to get the latest data from the database.
648+
The bookmark set in the cookie can be used to get the data from the database for a new session from that instance.
635649

636650
If you are using an external platform to manage your products, you can connect this API to the external platform, such that, when a product is created or updated in the external platform, the D1 database automatically updates the product details.
637651

0 commit comments

Comments
 (0)