Skip to content

Commit 48e79c0

Browse files
committed
Implementing feedback
1 parent e4a3ba5 commit 48e79c0

File tree

3 files changed

+19
-42
lines changed

3 files changed

+19
-42
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,17 @@ The following code snippet shows you how to store and retrieve data using the Du
2626
<TypeScriptExample>
2727
```ts
2828
export class Counter extends DurableObject {
29-
constructor(ctx: DurableObjectState, env: Env) {
30-
super(ctx, env);
31-
}
32-
33-
async increment(): Promise<number> {
34-
let value: number = (await this.ctx.storage.get('value')) || 0;
35-
value += 1;
36-
await this.ctx.storage.put('value', value);
37-
return value;
38-
}
39-
29+
constructor(ctx: DurableObjectState, env: Env) {
30+
super(ctx, env);
31+
}
32+
33+
async increment(): Promise<number> {
34+
let value: number = (await this.ctx.storage.get("value")) || 0;
35+
value += 1;
36+
await this.ctx.storage.put("value", value);
37+
return value;
38+
}
4039
}
41-
4240
```
4341
</TypeScriptExample>
4442

src/content/partials/durable-objects/api-storage-introduction.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ The Durable Object Storage API comes with several methods, including SQL, point-
1212
| -------------------- | ---------------------------------- | ------------------------------ |
1313
| SQL API |||
1414
| PITR API |||
15-
| KV API | ✅ <sup>2, 3</sup> ||
15+
| SynchronousKV API | ✅ <sup>2, 3</sup> ||
16+
| AsynchronousKV API | ✅ <sup>3</sup> ||
1617
| Alarms API |||
1718

1819
<Details header="Footnotes" open={true}>
@@ -22,8 +23,7 @@ its results are atomic and isolated from all other storage operations, even when
2223
accessing multiple key-value pairs.
2324

2425
<sup>2</sup> KV API methods like `get()`, `put()`, `delete()`, or `list()` store
25-
data in a hidden SQLite table.
26-
27-
<sup>3</sup> For SQLite-backed Durable Objects, you can use [synchronous KV API methods](/durable-objects/api/sqlite-storage-api/#synchronous-kv-api) using `ctx.storage.kv`. KV-backed Durable Objects use [asynchronous KV API methods](/durable-objects/api/legacy-kv-storage-api/#asynchronous-kv-api).
26+
data in a hidden SQLite table `__cf_kv`. Note that you will be able view this table when listing all tables, you will not be able to query it.
2827

28+
<sup>3</sup> SQLite-backed Durable Objects also use [synchronous KV API methods](/durable-objects/api/sqlite-storage-api/#synchronous-kv-api) using `ctx.storage.kv`, whereas KV-backed Durable Objects only provide [asynchronous KV API methods](/durable-objects/api/legacy-kv-storage-api/#asynchronous-kv-api).
2929
</Details>

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,25 @@ import {Type, MetaInfo} from "~/components";
66

77
### `get`
88

9-
- <code>ctx.storage.get(key <Type text="string" />, options <Type text="Object" />{" "}<MetaInfo text="optional" />)</code>: <Type text="Promise<any>" />
9+
- <code>ctx.storage.kv.get(key <Type text="string" />, options <Type text="Object" />{" "}<MetaInfo text="optional" />)</code>: <Type text="Any, undefined" />
1010
- Retrieves the value associated with the given key. The type of the returned value will be whatever was previously written for the key, or undefined if the key does not exist.
1111

12-
- <code>ctx.storage.get(keys <Type text="Array<string>" />, options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Promise<Map<string, any>>" />
13-
- Retrieves the values associated with each of the provided keys. 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. Results in the `Map` will be sorted in increasing order of their UTF-8 encodings, with any requested keys that do not exist being omitted. Supports up to 128 keys at a time.
14-
15-
#### Supported options
16-
17-
- `allowConcurrency`: <Type text='boolean' />
18-
- By default, the system will pause delivery of I/O events to the Object while a storage operation is in progress, in order to avoid unexpected race conditions. Pass `allowConcurrency: true` to opt out of this behavior and allow concurrent events to be delivered.
19-
20-
- `noCache`: <Type text='boolean'/>
21-
- If true, then the key/value will not be inserted into the in-memory cache. If the key is already in the cache, the cached value will be returned, but its last-used time will not be updated. Use this when you expect this key will not be used again in the near future. This flag is only a hint. This flag will never change the semantics of your code, but it may affect performance.
22-
2312
### `put`
2413

25-
- <code>put(key <Type text="string" />, value <Type text="any" />)</code>: <Type text="void" />
14+
- <code>ctx.storage.kv.put(key <Type text="string" />, value <Type text="any" />)</code>: <Type text="void" />
2615
- 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.
2716

2817
The size of keys and values have different limits depending on the Durable Object storage backend you are using. Refer to either:
29-
- [SQLite-backed Durable Object limits](/durable-objects/platform/limits/#sqlite-backed-durable-objects-general-limits)
30-
- [KV-backed Durable Object limits](/durable-objects/platform/limits/#key-value-backed-durable-objects-general-limits).<br/><br/>
31-
32-
- <code>put(entries <Type text="Object" />, options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Promise" />
33-
- Takes an Object and stores each of its keys and values to storage.
34-
- Each 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.
35-
- Supports up to 128 key-value pairs at a time. The size of keys and values have different limits depending on the flavor of Durable Object you are using. Refer to either:
36-
- [SQLite-backed Durable Object limits](/durable-objects/platform/limits/#sqlite-backed-durable-objects-general-limits)
37-
- [KV-backed Durable Object limits](/durable-objects/platform/limits/#key-value-backed-durable-objects-general-limits)
18+
- [SQLite-backed Durable Object limits](/durable-objects/platform/limits/#sqlite-backed-durable-objects-general-limits)<br/><br/>
3819

3920
### `delete`
4021

41-
- <code>delete(key <Type text="string" />)</code>: <Type text="boolean" />
22+
- <code>ctx.storage.kv.delete(key <Type text="string" />)</code>: <Type text="boolean" />
4223
- Deletes the key and associated value. Returns `true` if the key existed or `false` if it did not.
4324

44-
45-
4625
### `list`
4726

48-
- <code>list(options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Iterable<string, any>" />
27+
- <code>ctx.storage.kv.list(options <Type text="Object" /> <MetaInfo text="optional" />)</code>: <Type text="Iterable<string, any>" />
4928
- Returns all keys and values associated with the current Durable Object in ascending sorted order based on the keys' UTF-8 encodings.
5029
- 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.
5130

0 commit comments

Comments
 (0)