Skip to content

Commit 5b86e40

Browse files
OxyjunTimoWilhelm
authored andcommitted
[DO] KV API status clarification (cloudflare#22577)
* Changing SQLite-backed DO recommendation into partial * Apply suggestions from code review Co-authored-by: Timo Wilhelm <[email protected]> * Adding link to KV API, applying suggestion * Implementing feedback --------- Co-authored-by: Timo Wilhelm <[email protected]>
1 parent ec2f206 commit 5b86e40

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ The Durable Object Storage API allows <GlossaryTooltip term="Durable Object">Dur
1818

1919
The Durable Object Storage API comes with several methods, including SQL, point-in-time recovery (PITR), key-value (KV), and alarm APIs. Available API methods depend on the storage backend for a Durable Objects class, either [SQLite](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class) or [KV](/durable-objects/reference/durable-objects-migrations/#create-durable-object-class-with-key-value-storage).
2020

21-
:::note[Recommended SQLite-backed Durable Objects]
22-
Cloudflare recommends all new Durable Object classes use the [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class).
23-
24-
The [key-value storage backend](/durable-objects/reference/durable-objects-migrations/#create-durable-object-class-with-key-value-storage) remains for backwards compatibility, and a migration path from KV storage to SQLite storage for existing Durable Object classes will be available in the future.
25-
:::
26-
27-
<Render file="do-sqlite-storage-no-bill-note"/>
28-
2921
| Methods <sup>1</sup> | SQLite-backed Durable Object class | KV-backed Durable Object class |
3022
| ----------------------- | ---------------------------- | ------------------------ |
3123
| SQL API |||
@@ -43,6 +35,10 @@ The [key-value storage backend](/durable-objects/reference/durable-objects-migra
4335

4436
</Details>
4537

38+
<Render file="recommend-sqlite-do" product="durable-objects"/>
39+
40+
<Render file="do-sqlite-storage-no-bill-note"/>
41+
4642
## Access storage
4743

4844
Durable Objects gain access to Storage API via the `DurableObjectStorage` interface and accessed by the `DurableObjectState::storage` property. This is frequently accessed via `this.ctx.storage` with the `ctx` parameter passed to the Durable Object constructor.

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

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

1515
## Access storage
1616

17-
:::note[Recommended SQLite-backed Durable Objects]
18-
Cloudflare recommends all new Durable Object classes use the [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class).
19-
20-
The [key-value storage backend](/durable-objects/reference/durable-objects-migrations/#create-durable-object-class-with-key-value-storage) remains for backwards compatibility, and a migration path from KV storage to SQLite storage for existing Durable Object classes will be available in the future.
21-
:::
17+
<Render file="recommend-sqlite-do" product="durable-objects"/>
2218

2319
<Render file="do-sqlite-storage-no-bill-note"/>
2420

@@ -88,7 +84,7 @@ export class MyDurableObject extends DurableObject<Env> {
8884
async clearDo():Promise<void> {
8985
// If you've configured a Durable Object alarm
9086
await this.ctx.storage.deleteAlarm();
91-
87+
9288
// This will delete all the storage associated with this Durable Object instance
9389
// This will also delete the Durable Object instance itself
9490
await this.ctx.storage.deleteAll();
@@ -152,7 +148,7 @@ for (let row of cursor) {
152148
}
153149
```
154150

155-
You can represent the shape of any result type you wish, including more complex types. If you are performing a
151+
You can represent the shape of any result type you wish, including more complex types. If you are performing a
156152
`JOIN` across multiple tables, you can compose a type that reflects the results of your queries.
157153

158154
## Indexes in SQLite

src/content/docs/durable-objects/reference/durable-objects-migrations.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ new_sqlite_classes = ["DurableObjectAClass"]
8383

8484
### Create Durable Object class with key-value storage
8585

86-
:::note[Recommended SQLite-backed Durable Objects]
87-
Cloudflare recommends all new Durable Object classes use the [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class).
88-
89-
The key-value storage backend remains for backwards compatibility.
90-
:::
86+
<Render file="recommend-sqlite-do" product="durable-objects"/>
9187

9288
Use `new_classes` on the migration in your Worker's Wrangler file to create a Durable Object class with the key-value storage backend:
9389

@@ -269,7 +265,7 @@ transferred_classes = [{from = "DurableObjectExample", from_script = "OldWorkerS
269265

270266
- Migration tags are treated like unique names and are used to determine which migrations have already been applied. Once a given Worker code has a migration tag set on it, all future Worker code deployments must include a migration tag.
271267

272-
- The migration list is an ordered array of tables, specified as a key in your Wrangler configuration file.
268+
- The migration list is an ordered array of tables, specified as a key in your Wrangler configuration file.
273269

274270
- You can define the migration for each environment, as well as at the top level.
275271
- Top-level migration is specified at the top-level `migrations` key in the Wrangler configuration file.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
{}
3+
---
4+
5+
:::note[Recommended SQLite-backed Durable Objects]
6+
Cloudflare recommends all new Durable Object namespaces use the [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class). These Durable Objects can continue to use storage [key-value API](/durable-objects/api/storage-api/#kv-api).
7+
8+
Additionally, SQLite-backed Durable Objects allow you to store more types of data (such as tables), and offers Point In Time Recovery API which can restore a the Durable Object's embedded SQLite database contents (both SQL data and key-value data) to any point in the past 30 days.
9+
10+
The [key-value storage backend](/durable-objects/reference/durable-objects-migrations/#create-durable-object-class-with-key-value-storage) remains for backwards compatibility, and a migration path from KV storage backend to SQLite storage backend for existing Durable Object namespaces will be available in the future.
11+
:::

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,4 @@ Each method is implicitly wrapped inside a transaction, such that its results ar
1818
| KV API |||
1919
| Alarms API |||
2020

21-
:::note[Recommended SQLite-backed Durable Object]
22-
We recommend using SQLite-backed Durable Object over key-value backed Durable Object. SQLite-backed Durable Objects allow you to store more types of data (such as tables), and offers Point In Time Recovery API which can restore a the Durable Object's embedded SQLite database contents (both SQL data and key-value data) to any point in the past 30 days.
23-
:::
21+
<Render file="recommend-sqlite-do" product="durable-objects"/>

0 commit comments

Comments
 (0)