Skip to content

Commit 6a56e07

Browse files
committed
DO cleanup, adding table of APIs in storage-api.
1 parent 1d0db3e commit 6a56e07

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,8 @@ import {
1515

1616
The Durable Object Storage API allows <GlossaryTooltip term="Durable Object">Durable Objects</GlossaryTooltip> to access transactional and strongly consistent storage. A Durable Object's attached storage is private to its unique instance and cannot be accessed by other objects.
1717

18-
:::note[Scope of Durable Object storage]
19-
Note that Durable Object storage is scoped by individual <GlossaryTooltip term="Durable Object">Durable Objects</GlossaryTooltip>.
20-
21-
- An account can have many Durable Object <GlossaryTooltip term="namespace">namespaces</GlossaryTooltip>.
22-
- A namespace can have many Durable Objects.
23-
24-
However, storage is scoped per individual Durable Object.
25-
:::
26-
2718
<Render file="storage-intro-text"/>
2819

29-
JavaScript is a single-threaded and event-driven programming language. This means that JavaScript runtimes, by default, allow requests to interleave with each other which can lead to concurrency bugs. The Durable Objects runtime uses a combination of <GlossaryTooltip term="input gate">input gates</GlossaryTooltip> and <GlossaryTooltip term="output gate">output gates</GlossaryTooltip> to avoid this type of concurrency bug when performing storage operations.
30-
3120
The following code snippet shows you how to store and retrieve data using the Durable Object Storage API.
3221

3322
<TypeScriptExample>
@@ -49,8 +38,21 @@ export class Counter extends DurableObject {
4938
```
5039
</TypeScriptExample>
5140

41+
JavaScript is a single-threaded and event-driven programming language. This means that JavaScript runtimes, by default, allow requests to interleave with each other which can lead to concurrency bugs. The Durable Objects runtime uses a combination of <GlossaryTooltip term="input gate">input gates</GlossaryTooltip> and <GlossaryTooltip term="output gate">output gates</GlossaryTooltip> to avoid this type of concurrency bug when performing storage operations.
42+
43+
:::note[Scope of Durable Object storage]
44+
Note that Durable Object storage is scoped by individual <GlossaryTooltip term="Durable Object">Durable Objects</GlossaryTooltip>.
45+
46+
- An account can have many Durable Object <GlossaryTooltip term="namespace">namespaces</GlossaryTooltip>.
47+
- A namespace can have many Durable Objects.
48+
49+
However, storage is scoped per individual Durable Object.
50+
:::
51+
5252
## SQL API
5353

54+
<Render file="do-sqlite-storage-no-bill-note"/>
55+
5456
The `SqlStorage` interface encapsulates methods that modify the SQLite database embedded within a Durable Object. The `SqlStorage` interface is accessible via the [`sql` property](/durable-objects/api/storage-api/#) of `DurableObjectStorage` class.
5557

5658
For example, using `sql.exec()`, a user can create a table, then insert rows into the table.

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

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

1515
## Access storage
1616

17-
We recommend all new <GlossaryTooltip term="Durable Object class">Durable Object classes</GlossaryTooltip> use the SQLite storage backend. [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 key-value storage to SQL storage for existing Durable Object classes will be offered in the future.
17+
We recommend all new <GlossaryTooltip term="Durable Object class">Durable Object classes</GlossaryTooltip> use the SQLite storage backend.
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+
<Render file="do-sqlite-storage-no-bill-note"/>
22+
23+
:::note[Key-value storage]
24+
[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 key-value storage to SQL storage for existing Durable Object classes will be offered in the future.
25+
:::
26+
2127
### Create SQLite-backed Durable Object class
2228

2329
Use `new_sqlite_classes` on the migration in your Worker's Wrangler file:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ new_sqlite_classes = ["DurableObjectAClass"]
7575

7676
### Create Durable Object class with key-value storage
7777

78-
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.
78+
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.
7979

8080
Use `new_classes` on the migration in your Worker's Wrangler file:
8181

@@ -130,7 +130,7 @@ To delete a Durable Object binding `DEPRECATED_OBJECT`, your `wrangler.toml / wr
130130

131131
[[migrations]]
132132
tag = "v3" # Should be unique for each entry
133-
deleted_classes = ["DeprecatedObjectClass"] # Array of new classes
133+
deleted_classes = ["DeprecatedObjectClass"] # Array of deleted classes
134134
```
135135
</WranglerConfig>
136136
</Details>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
{}
3+
---
4+
5+
:::note[Storage billing on Durable Objects with SQLite storage backend]
6+
Storage billing is not yet enabled for Durable Object classes using SQLite storage backend. SQLite-backed Durable Objects will incur [charges for requests and duration](/durable-objects/platform/pricing/#compute-billing). Storage billing for Durable Objects using SQLite storage backend will be enabled at a later date with advance notice with the following pricing.
7+
:::

src/content/partials/durable-objects/durable-objects-pricing.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{}
33
---
44

5-
import { Markdown, GlossaryTooltip, Details, AnchorHeading } from "~/components";
5+
import {Render, Markdown, GlossaryTooltip, Details, AnchorHeading } from "~/components";
66

77
{ props.product === "durable-objects" && <><AnchorHeading title="Compute billing" depth={2}/></> }
88
{ props.product === "workers" && <><AnchorHeading title="Compute billing" depth={3}/></> }
@@ -52,9 +52,7 @@ The [Durable Objects Storage API](/durable-objects/api/storage-api) is only acce
5252
{ props.product === "durable-objects" && <><AnchorHeading title="SQLite storage backend" depth={3}/></> }
5353
{ props.product === "workers" && <><AnchorHeading title="SQLite storage backend" depth={4}/></> }
5454

55-
:::note
56-
Storage billing is not yet enabled for Durable Object classes using SQLite storage backend. SQLite-backed Durable Objects will incur [charges for requests and duration](/durable-objects/platform/pricing/#compute-billing). Storage billing for Durable Objects using SQLite storage backend will be enabled at a later date with advance notice with the following pricing.
57-
:::
55+
<Render file="do-sqlite-storage-no-bill-note"/>
5856

5957
| | Workers Free plan | Workers Paid plan |
6058
| ----------------------------- | ------------------------- | --------------------------------------------------------- |

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@ The Durable Object Storage API comes with several methods, including [SQL API](/
99
- Durable Objects gain access to a persistent KV Durable Object Storage API via the `DurableObjectStorage` interface and accessed by the `DurableObjectState::storage` property. This is frequently accessed via `this.ctx.storage` when the `ctx` parameter passed to the Durable Object constructor.
1010
- Durable Object classes with the key-value storage backend can only use KV API.
1111

12-
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.
12+
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.
13+
14+
| Type of storage API | SQLite backed Durable Object | KV backed Durable Object |
15+
| ------------------- | ---------------------------- | ------------------------ |
16+
| SQL API |||
17+
| PITR API |||
18+
| KV API |||
19+
| Alarms API |||
20+
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+
:::

0 commit comments

Comments
 (0)