You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/api/storage-api.mdx
+13-11Lines changed: 13 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,19 +15,8 @@ import {
15
15
16
16
The Durable Object Storage API allows <GlossaryTooltipterm="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.
17
17
18
-
:::note[Scope of Durable Object storage]
19
-
Note that Durable Object storage is scoped by individual <GlossaryTooltipterm="Durable Object">Durable Objects</GlossaryTooltip>.
20
-
21
-
- An account can have many Durable Object <GlossaryTooltipterm="namespace">namespaces</GlossaryTooltip>.
22
-
- A namespace can have many Durable Objects.
23
-
24
-
However, storage is scoped per individual Durable Object.
25
-
:::
26
-
27
18
<Renderfile="storage-intro-text"/>
28
19
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 <GlossaryTooltipterm="input gate">input gates</GlossaryTooltip> and <GlossaryTooltipterm="output gate">output gates</GlossaryTooltip> to avoid this type of concurrency bug when performing storage operations.
30
-
31
20
The following code snippet shows you how to store and retrieve data using the Durable Object Storage API.
32
21
33
22
<TypeScriptExample>
@@ -49,8 +38,21 @@ export class Counter extends DurableObject {
49
38
```
50
39
</TypeScriptExample>
51
40
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 <GlossaryTooltipterm="input gate">input gates</GlossaryTooltip> and <GlossaryTooltipterm="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 <GlossaryTooltipterm="Durable Object">Durable Objects</GlossaryTooltip>.
45
+
46
+
- An account can have many Durable Object <GlossaryTooltipterm="namespace">namespaces</GlossaryTooltip>.
47
+
- A namespace can have many Durable Objects.
48
+
49
+
However, storage is scoped per individual Durable Object.
50
+
:::
51
+
52
52
## SQL API
53
53
54
+
<Renderfile="do-sqlite-storage-no-bill-note"/>
55
+
54
56
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.
55
57
56
58
For example, using `sql.exec()`, a user can create a table, then insert rows into the table.
Copy file name to clipboardExpand all lines: src/content/docs/durable-objects/best-practices/access-durable-objects-storage.mdx
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,10 +14,16 @@ A Durable Object's [in-memory state](/durable-objects/reference/in-memory-state/
14
14
15
15
## Access storage
16
16
17
-
We recommend all new <GlossaryTooltipterm="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 <GlossaryTooltipterm="Durable Object class">Durable Object classes</GlossaryTooltip> use the SQLite storage backend.
18
18
19
19
[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.
20
20
21
+
<Renderfile="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
+
21
27
### Create SQLite-backed Durable Object class
22
28
23
29
Use `new_sqlite_classes` on the migration in your Worker's Wrangler file:
### Create Durable Object class with key-value storage
77
77
78
-
We recommend all new <GlossaryTooltipterm="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 <GlossaryTooltipterm="Durable Object class">Durable Object classes</GlossaryTooltip> use the SQLite storage backend. Key-value storage backend remains for backwards compatibility.
79
79
80
80
Use `new_classes` on the migration in your Worker's Wrangler file:
81
81
@@ -130,7 +130,7 @@ To delete a Durable Object binding `DEPRECATED_OBJECT`, your `wrangler.toml / wr
130
130
131
131
[[migrations]]
132
132
tag = "v3"# Should be unique for each entry
133
-
deleted_classes = ["DeprecatedObjectClass"] # Array of new classes
133
+
deleted_classes = ["DeprecatedObjectClass"] # Array of deleted classes
:::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.
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.
Copy file name to clipboardExpand all lines: src/content/partials/durable-objects/storage-intro-text.mdx
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,4 +9,15 @@ The Durable Object Storage API comes with several methods, including [SQL API](/
9
9
- 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.
10
10
- Durable Object classes with the key-value storage backend can only use KV API.
11
11
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 |
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.
0 commit comments