Skip to content

Commit e4a3ba5

Browse files
Apply suggestions from code review
Co-authored-by: Lambros Petrou <[email protected]>
1 parent 44b2810 commit e4a3ba5

File tree

3 files changed

+10
-47
lines changed

3 files changed

+10
-47
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar:
88
import { Render, Type, MetaInfo, GlossaryTooltip, TypeScriptExample, Details } from "~/components";
99

1010
:::note
11-
This page documents storage API for legacy KV-backed Durable Objects.
11+
This page documents the storage API for legacy KV-backed Durable Objects.
1212

1313
For the newer SQLite-backed Durable Object storage API, refer to [SQLite-backed Durable Object Storage](/durable-objects/api/sqlite-storage-api).
1414
:::
@@ -46,7 +46,7 @@ JavaScript is a single-threaded and event-driven programming language. This mean
4646

4747
## Asynchronous KV API
4848

49-
KV-backed Durable Objects use KV API methods which are asynchronous.
49+
KV-backed Durable Objects provide KV API methods which are asynchronous.
5050

5151
<Render file="api-async-kv-legacy" product="durable-objects" />
5252

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar:
88
import { Render, Type, MetaInfo, GlossaryTooltip, TypeScriptExample, Details } from "~/components";
99

1010
:::note
11-
This page documents storage API for the newer SQLite-backed Durable Objects.
11+
This page documents the storage API for the newer SQLite-backed Durable Objects.
1212

1313
For the legacy KV-backed Durable Object storage API, see [KV-backed Durable Object Storage (Legacy)](/durable-objects/api/legacy-kv-storage-api/).
1414
:::
@@ -50,7 +50,7 @@ JavaScript is a single-threaded and event-driven programming language. This mean
5050

5151
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/sqlite-storage-api/#sql) of `DurableObjectStorage` class.
5252

53-
For example, using `sql.exec()`, a user can create a table, then insert rows into the table.
53+
For example, using `sql.exec()` a user can create a table and insert rows.
5454

5555
```ts
5656
import { DurableObject } from "cloudflare:workers";
@@ -75,8 +75,8 @@ export class MyDurableObject extends DurableObject {
7575
}
7676
```
7777

78-
- SQL API methods accessed with `ctx.storage.sql` are only allowed on [Durable Object classes with SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class) and will return an error if called on Durable Object classes with a key-value storage backend.
79-
- When writing data, every index counts as an additional row. However, indexes may be beneficial for read-heavy use cases. Refer to [Index for SQLite Durable Objects](/durable-objects/best-practices/access-durable-objects-storage/#index-for-sqlite-durable-objects).
78+
- SQL API methods accessed with `ctx.storage.sql` are only allowed on [Durable Object classes with SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#create-sqlite-backed-durable-object-class) and will return an error if called on Durable Object classes with a KV-storage backend.
79+
- When writing data, every row update of an index counts as an additional row. However, indexes may be beneficial for read-heavy use cases. Refer to [Index for SQLite Durable Objects](/durable-objects/best-practices/access-durable-objects-storage/#index-for-sqlite-durable-objects).
8080
- Writing data to [SQLite virtual tables](https://www.sqlite.org/vtab.html) also counts towards rows written.
8181

8282
<Render file="d1-do-supported-sqlite-extensions" product="d1" params={{ product: "Durable Objects support" }}/>

src/content/partials/durable-objects/api-sync-kv.mdx

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {Type, MetaInfo} from "~/components";
2222

2323
### `put`
2424

25-
- <code>put(key <Type text="string" />, value <Type text="any" />, options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Promise" />
25+
- <code>put(key <Type text="string" />, value <Type text="any" />)</code>: <Type text="void" />
2626
- Stores the value and associates it with the given key. The value can be any type supported by the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), which is true of most types.
2727

2828
The size of keys and values have different limits depending on the Durable Object storage backend you are using. Refer to either:
@@ -38,47 +38,16 @@ import {Type, MetaInfo} from "~/components";
3838

3939
### `delete`
4040

41-
- <code>delete(key <Type text="string" />, options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Promise<boolean>" />
41+
- <code>delete(key <Type text="string" />)</code>: <Type text="boolean" />
4242
- Deletes the key and associated value. Returns `true` if the key existed or `false` if it did not.
4343

44-
- <code>delete(keys <Type text="Array<string>" />, options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Promise<number>" />
45-
- Deletes the provided keys and their associated values. Supports up to 128 keys at a time. Returns a count of the number of key-value pairs deleted.
4644

47-
#### Supported options
48-
49-
- `put()`, `delete()` and `deleteAll()` support the following options:
50-
51-
- `allowUnconfirmed` <Type text ='boolean' />
52-
- By default, the system will pause outgoing network messages from the Durable Object until all previous writes have been confirmed flushed to disk. If the write fails, the system will reset the Object, discard all outgoing messages, and respond to any clients with errors instead.
53-
54-
- This way, Durable Objects can continue executing in parallel with a write operation, without having to worry about prematurely confirming writes, because it is impossible for any external party to observe the Object's actions unless the write actually succeeds.
55-
56-
- After any write, subsequent network messages may be slightly delayed. Some applications may consider it acceptable to communicate on the basis of unconfirmed writes. Some programs may prefer to allow network traffic immediately. In this case, set `allowUnconfirmed` to `true` to opt out of the default behavior.
57-
58-
- If you want to allow some outgoing network messages to proceed immediately but not others, you can use the allowUnconfirmed option to avoid blocking the messages that you want to proceed and then separately call the [`sync()`](#sync) method, which returns a promise that only resolves once all previous writes have successfully been persisted to disk.
59-
60-
- `noCache` <Type text ='boolean' />
61-
- If true, then the key/value will be discarded from memory as soon as it has completed writing to disk.
62-
63-
- Use `noCache` if the key will not be used again in the near future. `noCache` will never change the semantics of your code, but it may affect performance.
64-
65-
- If you use `get()` to retrieve the key before the write has completed, the copy from the write buffer will be returned, thus ensuring consistency with the latest call to `put()`.
66-
67-
:::note[Automatic write coalescing]
68-
69-
If you invoke `put()` (or `delete()`) multiple times without performing any `await` in the meantime, the operations will automatically be combined and submitted atomically. In case of a machine failure, either all of the writes will have been stored to disk or none of the writes will have been stored to disk.
70-
:::
71-
72-
:::note[Write buffer behavior]
73-
74-
The `put()` method returns a `Promise`, but most applications can discard this promise without using `await`. The `Promise` usually completes immediately, because `put()` writes to an in-memory write buffer that is flushed to disk asynchronously. However, if an application performs a large number of `put()` without waiting for any I/O, the write buffer could theoretically grow large enough to cause the isolate to exceed its 128 MB memory limit. To avoid this scenario, such applications should use `await` on the `Promise` returned by `put()`. The system will then apply backpressure onto the application, slowing it down so that the write buffer has time to flush. Using `await` will disable automatic write coalescing.
75-
:::
7645

7746
### `list`
7847

79-
- <code>list(options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Promise<Map<string, any>>" />
48+
- <code>list(options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Iterable<string, any>" />
8049
- Returns all keys and values associated with the current Durable Object in ascending sorted order based on the keys' UTF-8 encodings.
81-
- The type of each returned value in the [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) will be whatever was previously written for the corresponding key.
50+
- The type of each returned value in the [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol) will be whatever was previously written for the corresponding key.
8251

8352
- Be aware of how much data may be stored in your Durable Object before calling this version of `list` without options because all the data will be loaded into the Durable Object's memory, potentially hitting its [limit](/durable-objects/platform/limits/). If that is a concern, pass options to `list` as documented below.
8453

@@ -102,9 +71,3 @@ The `put()` method returns a `Promise`, but most applications can discard this p
10271

10372
- `limit` <Type text ='number' />
10473
- Maximum number of key-value pairs to return.
105-
106-
- `allowConcurrency` <Type text ='boolean' />
107-
- Same as the option to `get()`, above.
108-
109-
- `noCache` <Type text ='boolean' />
110-
- Same as the option to `get()`, above.

0 commit comments

Comments
 (0)