Skip to content

Commit 16222db

Browse files
committed
Improved text
1 parent 31e9b75 commit 16222db

File tree

1 file changed

+27
-22
lines changed
  • src/content/docs/pipelines/tutorials/query-data-with-motherduck

1 file changed

+27
-22
lines changed

src/content/docs/pipelines/tutorials/query-data-with-motherduck/index.mdx

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ updated: 2025-02-24
33
difficulty: Intermediate
44
content_type: 📝 Tutorial
55
pcx_content_type: tutorial
6-
title: Analyzing Clickstream Data with MotherDuck and Cloudflare R2
6+
title: Ingest data from a Worker, and analyze using MotherDuck
77
products:
88
- R2
99
- Workers
@@ -13,17 +13,18 @@ languages:
1313
- SQL
1414
---
1515

16-
import { Render, PackageManagers, Details } from "~/components";
16+
import { Render, PackageManagers, Details, WranglerConfig } from "~/components";
1717

18-
In this tutorial, you will learn how to ingest clickstream data to a R2 bucket using Pipelines. You will also learn how to connect the bucket to MotherDuck. You will then query the data using MotherDuck.
18+
In this tutorial, you will learn how to ingest clickstream data from your website, using Pipelines. We'll also use Pipelines to load this data into an [R2 bucket](/r2/). You will also learn how to connect the bucket to MotherDuck. You will then query the data using MotherDuck.
1919

20-
For this tutorial, you will build a landing page of an e-commerce website. The page will list the products available for sale. A user can click on the view button to view the product details or click on the add to cart button to add the product to their cart. The focus of this tutorial is to show how to ingest the data to R2 and query it using MotherDuck. Hence, the landing page will be a simple HTML page with no functionality.
20+
For this tutorial, you will build a landing page of an e-commerce website. A user can click on the view button to view the product details or click on the add to cart button to add the product to their cart.
21+
22+
We will use a pipeline to ingest these click events, and load into an R2 bucket. We'll then use MotherDuck to query the events.
2123

2224
## Prerequisites
2325

24-
1. Create a [R2 bucket](/r2/buckets/create-buckets/) in your Cloudflare account.
25-
2. A [MotherDuck](https://motherduck.com/) account.
26-
3. Install [`Node.js`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
26+
1. A [MotherDuck](https://motherduck.com/) account.
27+
2. Install [`Node.js`](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
2728

2829
<Details header="Node.js version manager">
2930
Use a Node version manager like [Volta](https://volta.sh/) or
@@ -49,7 +50,7 @@ Create a new Worker project by running the following commands:
4950
product="workers"
5051
params={{
5152
category: "hello-world",
52-
type: "Hello World Worker",
53+
type: "Worker only",
5354
lang: "TypeScript",
5455
}}
5556
/>
@@ -60,20 +61,24 @@ Navigate to the `e-commerce-pipelines` directory:
6061
cd e-commerce-pipelines
6162
```
6263

63-
## 2. Create the front-end
64+
## 2. Create the frontend
6465

6566
Using Static Assets, you can serve the frontend of your application from your Worker. To use Static Assets, you need to add the required bindings to your `wrangler.toml` file.
6667

68+
<WranglerConfig>
69+
6770
```toml
6871
[assets]
6972
directory = "public"
7073
```
7174

72-
Next, create a `public` directory and add an `index.html` file. The `index.html` file should contain the following HTML code:
75+
</WranglerConfig>
76+
77+
Next, create a `public` directory in the root of your project. Add an `index.html` file to the `public` directory. The `index.html` file should contain the following HTML code:
7378

7479
<details>
7580
<summary>Select to view the HTML code</summary>
76-
```html
81+
```html
7782
<!DOCTYPE html>
7883
<html>
7984
<head>
@@ -182,7 +187,7 @@ Next, create a `public` directory and add an `index.html` file. The `index.html`
182187
</body>
183188

184189
</html>
185-
190+
186191
```
187192
</details>
188193

@@ -302,26 +307,28 @@ The `handleClick` function does the following:
302307
- Creates a `POST` request to the `/api/clickstream` endpoint with the data.
303308
- Logs any errors that occur.
304309

305-
## 4. Create a pipeline
310+
## 4. Create an R2 bucket
311+
We'll create a new R2 bucket to use as the sink for our pipeline. Create a new r2 bucket `clickstream-data` using the [Wrangler CLI](/workers/wrangler/):
306312

307-
You need to create a new pipeline and connect it to your R2 bucket.
313+
```sh
314+
npx wrangler r2 bucket create clickstream-data
315+
```
316+
317+
## 5. Create a pipeline
318+
You need to create a new pipeline and connect it to the R2 bucket we created in the previous step.
308319

309320
Create a new pipeline `clickstream-pipeline` using the [Wrangler CLI](/workers/wrangler/):
310321

311322
```sh
312-
npx wrangler pipelines create clickstream-pipeline --r2 <BUCKET_NAME>
323+
npx wrangler pipelines create clickstream-pipeline --r2-bucket clickstream-data
313324
```
314325

315-
Replace `<BUCKET_NAME>` with the name of your R2 bucket.
316-
317326
When you run the command, you will be prompted to authorize Cloudflare Workers Pipelines to create R2 API tokens on your behalf. These tokens are required by your Pipeline. Your Pipeline uses these tokens when loading data into your bucket. You can approve the request through the browser link which will open automatically.
318327

319328
```output
320-
🌀 Authorizing R2 bucket <BUCKET_NAME>
329+
🌀 Authorizing R2 bucket clickstream-data
321330
🌀 Creating pipeline named "clickstream-pipeline"
322331
✅ Successfully created pipeline "clickstream-pipeline" with id <PIPELINES_ID>
323-
You can now send data to your pipeline with:
324-
curl "https://<PIPELINES_ID>.pipelines.cloudflare.com" -d '[{"foo": "bar"}]'
325332
```
326333

327334
## 5. Send clickstream data to your pipeline
@@ -330,8 +337,6 @@ The front-end of the application makes a call to the `/api/clickstream` endpoint
330337

331338
You will use the pipelines binding to send the clickstream data to your pipeline. In your `wrangler` file, add the following bindings:
332339

333-
import { WranglerConfig } from "~/components";
334-
335340
<WranglerConfig>
336341

337342
```toml

0 commit comments

Comments
 (0)