Skip to content

Commit 5c9ea0d

Browse files
committed
pm edits for sqlite ga
1 parent c8e0f01 commit 5c9ea0d

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,28 @@ A Durable Object's [in-memory state](/durable-objects/reference/in-memory-state/
1414

1515
## Access storage
1616

17-
By default, a <GlossaryTooltip term="Durable Object class">Durable Object class</GlossaryTooltip> leverages a SQLite storage backend.
17+
We recommend all new <GlossaryTooltip term="Durable Object class">Durable Object classes</GlossaryTooltip> use the SQLite storage backend. Key-value storage backend remains for backwards compatibility, and a migration path from key-value storage to SQL storage for existing Durable Object classes will be offered in the future.
1818

1919
[Storage API methods](/durable-objects/api/storage-api/#methods) are available on `ctx.storage` parameter passed to the Durable Object constructor. Storage API has SQL APIs and key-value APIs. Only Durable Object classes with a SQLite storage backend can access SQL API.
2020

21+
### Wrangler configuration for SQLite-backed Durable Objects
22+
23+
Use `new_sqlite_classes` on the migration in your Worker's Wrangler file:
24+
25+
<WranglerConfig>
26+
27+
```toml
28+
[[migrations]]
29+
tag = "v1" # Should be unique for each entry
30+
new_sqlite_classes = ["MyDurableObject"] # Array of new classes
31+
```
32+
33+
</WranglerConfig>
34+
35+
[SQL API](/durable-objects/api/sql-storage/#exec) is available on `ctx.storage.sql` parameter passed to the Durable Object constructor.
36+
37+
### Initialize instance variables from storage
38+
2139
A common pattern is to initialize a Durable Object from [persistent storage](/durable-objects/api/storage-api/) and set instance variables the first time it is accessed. Since future accesses are routed to the same Durable Object, it is then possible to return any initialized values without making further calls to persistent storage.
2240

2341
```ts
@@ -42,38 +60,23 @@ export class Counter extends DurableObject {
4260
}
4361
}
4462
```
63+
4564
### Remove a Durable Object's storage
4665

4766
A Durable Object fully ceases to exist if, when it shuts down, its storage is empty. If you never write to a Durable Object's storage at all (including setting <GlossaryTooltip term="alarm">alarms</GlossaryTooltip>), then storage remains empty, and so the Durable Object will no longer exist once it shuts down.
4867

4968
However if you ever write using [Storage API](/durable-objects/api/storage-api/), including setting alarms, then you must explicitly call [`storage.deleteAll()`](/durable-objects/api/storage-api/#deleteall) to empty storage. It is not sufficient to simply delete the specific data that you wrote, such as deleting a key or dropping a table, as some metadata may remain. The only way to remove all storage is to call `deleteAll()`. Calling `deleteAll()` ensures that a Durable Object will not be billed for storage.
5069

51-
## Wrangler configuration for SQLite Durable Objects
52-
53-
Use `new_sqlite_classes` on the migration in your Worker's Wrangler file:
54-
55-
<WranglerConfig>
56-
57-
```toml
58-
[[migrations]]
59-
tag = "v1" # Should be unique for each entry
60-
new_sqlite_classes = ["MyDurableObject"] # Array of new classes
61-
```
62-
63-
</WranglerConfig>
64-
65-
[SQL API](/durable-objects/api/sql-storage/#exec) is available on `ctx.storage.sql` parameter passed to the Durable Object constructor.
66-
67-
## Examples
70+
## SQL API Examples
6871

6972
<Render file="durable-objects-sql" />
7073

71-
<Render file="durable-objects-vs-d1" />
72-
73-
## Index for SQLite Durable Objects
74+
## Indexes in SQLite
7475

7576
Creating indexes for your most queried tables and filtered columns reduces how much data is scanned and improves query performance at the same time. If you have a read-heavy workload (most common), this can be particularly advantageous. Writing to columns referenced in an index will add at least one (1) additional row written to account for updating the index, but this is typically offset by the reduction in rows read due to the benefits of an index.
7677

78+
<Render file="durable-objects-vs-d1" />
79+
7780
## Related resources
7881

7982
* [Zero-latency SQLite storage in every Durable Object blog post](https://blog.cloudflare.com/sqlite-in-durable-objects)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Move into your new directory:
5252
cd durable-object-starter
5353
```
5454

55-
## 2. Write a Durable Object class
55+
## 2. Write a Durable Object class using SQL API
5656

5757
Before you create and access a Durable Object, its behavior must be defined by an ordinary exported JavaScript class.
5858

src/content/docs/durable-objects/index.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ head:
1313
import { Render, CardGrid, Description, Feature, LinkTitleCard, Plan, RelatedProduct, LinkButton } from "~/components"
1414

1515
<Description>
16-
Create collaborative applications, real-time chat, multiplayer games and more without needing to coordinate state or manage infrastructure.
16+
Create AI agents, collaborative applications, real-time interactions like chat or multiplayer games, and more without needing to coordinate state or manage infrastructure.
1717
</Description>
1818

1919
<Plan type="workers-all" />
2020

2121
Durable Objects provide a building block for stateful applications and distributed systems.
2222

23-
Use Durable Objects to build applications that need coordination among multiple clients, like collaborative editing tools, interactive chat, multiplayer games, and deep distributed systems, without requiring you to build serialization and coordination primitives on your own.
23+
Use Durable Objects to build applications that need coordination among multiple clients, like collaborative editing tools, interactive chat, multiplayer games, live notifications, and deep distributed systems, without requiring you to build serialization and coordination primitives on your own.
2424

2525
<LinkButton href="/durable-objects/get-started/">Get started</LinkButton>
2626

2727
:::note
28-
SQLite-backed Durable Objects have now reached GA.
28+
SQLite-backed Durable Objects are now available on the Workers Free plan with these [limits](/durable-objects/platform/pricing/).
2929

30-
You can use SQLite-backed Durable Objects with the Workers Free plan.
30+
SQLite storage and [SQL API](/durable-objects/api/sql-storage/) have moved from beta to general availability. New Durable Object classes should use wrangler configuration for [SQLite storage](/durable-objects/best-practices/access-durable-objects-storage/#wrangler-configuration-for-sqlite-durable-objects).
3131
:::
3232

3333
### What are Durable Objects?

src/content/partials/durable-objects/storage-intro-text.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
The Durable Object Storage API comes with several methods, including key-value (KV) API, SQL API, and point-in-time-recovery (PITR) API.
66

7-
- Durable Object classes with the default, [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend) can use KV API, SQL API, and PITR API. KV API methods like `get()`, `put()`, `delete()`, or `list()` store data in a hidden SQLite table.
7+
- Durable Object classes with the recommended, [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend) can use KV API, SQL API, and PITR API. KV API methods like `get()`, `put()`, `delete()`, or `list()` store data in a hidden SQLite table.
88
- Specifically for Durable Object classes with SQLite storage backend, KV operations which were previously asynchronous (for example, [`get`](/durable-objects/api/storage-api/#get), [`put`](/durable-objects/api/storage-api/#put), [`delete`](/durable-objects/api/storage-api/#delete), [`deleteAll`](/durable-objects/api/storage-api/#deleteall), [`list`](/durable-objects/api/storage-api/#list)) are synchronous, even though they return promises. These methods will have completed their operations before they return the promise.
9-
- Durable Object classes with the key-value storage backend can use KV API.
9+
- Durable Object classes with the key-value storage backend can only use KV API.
1010

1111
Each method is implicitly wrapped inside a transaction, such that its results are atomic and isolated from all other storage operations, even when accessing multiple key-value pairs.

0 commit comments

Comments
 (0)