Skip to content

Commit ec86dd9

Browse files
harshil1712vy-tonkentonvOxyjun
authored
[DO] Add seat booking app tutorial (#17063)
* SQLite in Durable Objects docs: - Add DO SQL class migration, API, pricing, limits, and changelog. - Update DO glossary * Update src/content/docs/durable-objects/api/transactional-storage-api.mdx Co-authored-by: Kenton Varda <[email protected]> * Update src/content/docs/durable-objects/api/transactional-storage-api.mdx Co-authored-by: Kenton Varda <[email protected]> * Update src/content/partials/durable-objects/durable-objects-sql.mdx Co-authored-by: Kenton Varda <[email protected]> * Update src/content/partials/workers/transactional_storage_api_pricing.mdx Co-authored-by: Kenton Varda <[email protected]> * Address initial feedback - Rename "Transactional Storage API" to "Storage API" * Document next(), toArray(), and one() * Fix indentation, complete rename from Transactional Storage API to Storage API * Fix code formatting * Fix code formate * Fix render link * Clarify billing * Fix redirect * add seat booking tutorial * feedback changes and links update * remove old code * update HTML code to handle WS link on deploy * Resolving merge conflict part 2 * Correcting typo in changelog. * fix category * Update src/content/docs/durable-objects/tutorials/build-a-seat-booking-app/index.mdx Co-authored-by: Vy Ton <[email protected]> * Update src/content/docs/durable-objects/tutorials/build-a-seat-booking-app/index.mdx Co-authored-by: Vy Ton <[email protected]> * Update src/content/docs/durable-objects/tutorials/build-a-seat-booking-app/index.mdx Co-authored-by: Vy Ton <[email protected]> * update class name and add toArray method --------- Co-authored-by: Vy Ton <[email protected]> Co-authored-by: Kenton Varda <[email protected]> Co-authored-by: Jun Lee <[email protected]>
1 parent 4cf6d1a commit ec86dd9

File tree

8 files changed

+681
-15
lines changed

8 files changed

+681
-15
lines changed

src/content/changelogs/durable-objects.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ entries:
1111
An issue was identified with [alarms](/durable-objects/api/alarms/) in [beta Durable Object classes with a SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend). Alarms have been temporarily disabled for only SQLite-backed Durable Objects while a fix is implemented. Alarms in Durable Objects with default, key-value storage backend are unaffected and continue to operate.
1212
1313
- publish_date: "2024-09-26"
14-
title: (Beta) SQLite storage backend & SQL API availabe on new Durable Object classes
14+
title: (Beta) SQLite storage backend & SQL API available on new Durable Object classes
1515
description: |-
1616
The new beta version of Durable Objects is available where each Durable Object has a private, embedded SQLite database. When deploying a new Durable Object class, users can [opt-in to a SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend) in order to access new [SQL API](/durable-objects/api/storage-api/#sqlexec) and [point-in-time-recovery API](/durable-objects/api/storage-api/#point-in-time-recovery), part of Durable Objects Storage API.
1717

src/content/docs/durable-objects/api/storage-api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,4 @@ The PITR API represents points in times using "bookmarks". A bookmark is a mostl
332332
### Related resources
333333

334334
* [Durable Objects: Easy, Fast, Correct – Choose Three](https://blog.cloudflare.com/durable-objects-easy-fast-correct-choose-three/).
335-
* [WebSockets API](/durable-objects/api/websockets/).
335+
* [WebSockets API](/durable-objects/api/websockets/).

src/content/docs/durable-objects/best-practices/access-durable-objects-storage.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Render } from "~/components";
1010

1111
Durable Objects are a powerful compute API that provides a compute with storage building block. Each Durable Object has its own private, transactional and strongly consistent storage. Durable Objects [Storage API](/durable-objects/api/storage-api/#methods) provides access to a Durable Object's attached storage.
1212

13-
A Durable Object's [in-memory state](/durable-objects/reference/in-memory-state/) is preserved as long as the Durable Object is not evicted from memory. Inactive Durable Objects with no incoming request traffic can be evicted. There are normal operations like [code deployments](/workers/configuration/versions-and-deployments/) that trigger Durable Objects to restart and lose their in-memory state. For these reasons, you should use Storage API to persist state durably on disk that needs to survive eviction or restart of Durable Objects.
13+
A Durable Object's [in-memory state](/durable-objects/reference/in-memory-state/) is preserved as long as the Durable Object is not evicted from memory. Inactive Durable Objects with no incoming request traffic can be evicted. There are normal operations like [code deployments](/workers/configuration/versions-and-deployments/) that trigger Durable Objects to restart and lose their in-memory state. For these reasons, you should use Storage API to persist state durably on disk that needs to survive eviction or restart of Durable Objects.
1414

1515
## Access storage
1616

src/content/docs/durable-objects/get-started/walkthrough.mdx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ Your `MyDurableObject` class will have a constructor with two parameters. The fi
7171
<Tabs> <TabItem label="JavaScript" icon="seti:javascript">
7272

7373
```js
74-
export class MyDurableObject {
74+
export class MyDurableObject extends DurableObject{
7575
constructor(state, env) {}
7676
}
7777
```
7878

7979
</TabItem> <TabItem label="TypeScript" icon="seti:typescript">
8080

8181
```ts
82-
export class MyDurableObject {
82+
export class MyDurableObject extends DurableObject{
8383
constructor(state: DurableObjectState, env: Env) {}
8484
}
8585
```
@@ -93,7 +93,7 @@ Your file should now look like:
9393
<Tabs> <TabItem label="JavaScript" icon="seti:javascript">
9494

9595
```js
96-
export class MyDurableObject {
96+
export class MyDurableObject extends DurableObject{
9797
constructor(state, env) {}
9898

9999
async fetch(request) {
@@ -105,7 +105,7 @@ export class MyDurableObject {
105105
</TabItem> <TabItem label="TypeScript" icon="seti:typescript">
106106

107107
```ts
108-
export class MyDurableObject {
108+
export class MyDurableObject extends DurableObject{
109109
constructor(state: DurableObjectState, env: Env) {}
110110

111111
async fetch(request: Request) {
@@ -218,6 +218,24 @@ tag = "v1" # Should be unique for each entry
218218
new_classes = ["MyDurableObject"] # Array of new classes
219219
```
220220

221+
### 6.a Optional: Configure new Durable Object class for SQL storage
222+
223+
:::note[SQLite in Durable Objects Beta]
224+
225+
New beta version of Durable Objects is available where each Durable Object has a private, embedded SQLite database. SQL storage is opt-in during beta; otherwise, a Durable Object class has the standard, private key-value storage. Objects can access long-lived durable storage with the [Storage API](/durable-objects/api/storage-api/).
226+
227+
:::
228+
229+
A Durable Object class can only have a single storage type, which cannot be changed after the Durable Object class is created.
230+
231+
To configure SQL storage and API, replace `new_classes` with `new_sqlite_classes` in your Worker's `wrangler.toml` file:
232+
233+
```toml
234+
[[migrations]]
235+
tag = "v1" # Should be unique for each entry
236+
new_sqlite_classes = ["MyDurableObject"] # Array of new classes
237+
```
238+
221239
Refer to [Durable Objects migrations](/durable-objects/reference/durable-objects-migrations/) to learn more about the migration process.
222240

223241
## 7. Develop a Durable Object Worker locally

0 commit comments

Comments
 (0)