Skip to content

Commit b2bccd1

Browse files
committed
Initialising withSession in the D1 API docs
1 parent c769b63 commit b2bccd1

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,25 @@ return new Response(dump, {
241241

242242
#### Return values
243243

244-
- None.
244+
- None.
245+
246+
### `withSession`
247+
248+
Starts a D1 Session which activates read replication.
249+
250+
```js
251+
const session = env.DB.withSession("<constraint> or bookmark");
252+
```
253+
254+
#### Parameters
255+
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.
260+
261+
- <code>bookmark</code>: <Type text="String?"/><MetaInfo text="Optional"/>
262+
- 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.
263+
264+
#### Return values
265+

0 commit comments

Comments
 (0)