Skip to content

Commit 79a6785

Browse files
committed
Updating api playground, minor rephrasing
1 parent ca8a352 commit 79a6785

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/content/docs/d1/worker-api/d1-database.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ const session = env.DB.withSession("<constraint> or bookmark");
253253

254254
#### Parameters
255255

256-
- <code>condition</code>: <Type text="String"/><MetaInfo text="Optional"/>
257-
- The starting condition for the D1 Session. `<constraint>` can be one of:
258-
- `first-primary`: Directs the first query in the Session (whether read or write) to the primary database instance. This option is useful if you need to start the Session with the most up-to-date data from the primary database instance.
259-
- `first-unconstrained`: Directs the first query in the Session (whether read or write) to any database instance. This option is useful if you do not need to start the Session with the most up-to-date data, and wish to prioritize minimizing query latency from the very start of the Session.
256+
- <code>constraint</code>: <Type text="String"/><MetaInfo text="Optional"/>
257+
- The starting condition for the D1 Session. `<constraint>` can be one of two:
258+
- `first-primary`: Directs the first query in the Session (whether read or write) to the primary database instance. Use this option if you need to start the Session with the most up-to-date data from the primary database instance.
259+
- `first-unconstrained`: Directs the first query in the Session (whether read or write) to any database instance. Use this option if you do not need to start the Session with the most up-to-date data, and wish to prioritize minimizing query latency from the very start of the Session.
260260

261-
- <code>bookmark</code>: <Type text="String?"/><MetaInfo text="Optional"/>
261+
- <code>bookmark</code>: <Type text="String"/><MetaInfo text="Optional"/>
262262
- A [`bookmark`](/d1/reference/time-travel/#bookmarks) from an existing D1 Session. This allows you to continue the existing Session using the `bookmark` as a reference point.
263263

264264
#### Return values

src/content/docs/d1/worker-api/index.mdx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ Replace the contents of your `index.js` file with the code below to view the eff
8181
export default {
8282
async fetch(request, env) {
8383
const { pathname } = new URL(request.url);
84-
8584
// if (pathname === "/api/beverages") {
8685
// // If you did not use `DB` as your binding name, change it here
8786
// const { results } = await env.DB.prepare("SELECT * FROM Customers WHERE CompanyName = ?",).bind("Bs Beverages").all();
8887
// return Response.json(results);
8988
// }
90-
9189
const companyName1 = `Bs Beverages`;
9290
const companyName2 = `Around the Horn`;
9391
const stmt = env.DB.prepare(`SELECT * FROM Customers WHERE CompanyName = ?`);
92+
const stmtMulti = env.DB.prepare(`SELECT * FROM Customers; SELECT * FROM Customers WHERE CompanyName = ?`);
93+
const session = env.DB.withSession("first-primary")
94+
const sessionStmt = session.prepare(`SELECT * FROM Customers WHERE CompanyName = ?`);
9495

9596
if (pathname === `/RUN`){
9697
const returnValue = await stmt.bind(companyName1).run();
@@ -114,42 +115,42 @@ export default {
114115
} else if (pathname === `/EXEC`){
115116
const returnValue = await env.DB.exec(`SELECT * FROM Customers WHERE CompanyName = "Bs Beverages"`);
116117
return Response.json(returnValue);
118+
119+
} else if (pathname === `/WITHSESSION`){
120+
const returnValue = await sessionStmt.bind(companyName1).run();
121+
console.log("You're now using D1 Sessions!")
122+
return Response.json(returnValue);
117123
}
118124

119125
return new Response(
120126
`Welcome to the D1 API Playground!
121127
\nChange the URL to test the various methods inside your index.js file.`,
122128
);
123129
},
124-
};
125-
130+
};
126131
```
127132
</Details>
128133

129134
### 3. Deploy the Worker
130135

131136
<Steps>
132137
1. Navigate to your tutorial directory you created by following step 1.
133-
2. Run `npx wrangler dev`.
138+
2. Run `npx wrangler deploy`.
134139
```sh
135-
npx wrangler dev
140+
npx wrangler deploy
136141
```
137142
```sh output
138-
⛅️ wrangler 3.85.0 (update available 3.86.1)
139-
-------------------------------------------------------
143+
⛅️ wrangler 3.112.0
144+
--------------------
140145

146+
Total Upload: 1.90 KiB / gzip: 0.59 KiB
141147
Your worker has access to the following bindings:
142148
- D1 Databases:
143-
- DB: <DATABASE_NAME> (DATABASE_ID) (local)
144-
⎔ Starting local server...
145-
[wrangler:inf] Ready on http://localhost:8787
146-
╭───────────────────────────╮
147-
│ [b] open a browser │
148-
│ [d] open devtools │
149-
│ [l] turn off local mode │
150-
│ [c] clear console │
151-
│ [x] to exit
152-
╰───────────────────────────╯
149+
- DB: DATABASE_NAME (<DATABASE_ID>)
150+
Uploaded WORKER_NAME (7.01 sec)
151+
Deployed WORKER_NAME triggers (1.25 sec)
152+
https://jun-d1-rr.d1-sandbox.workers.dev
153+
Current Version ID: VERSION_ID
153154
```
154155
3. Open a browser at the specified address.
155156
</Steps>

0 commit comments

Comments
 (0)