diff options
author | Heyang Zhou <zhy20000919@hotmail.com> | 2023-03-24 20:06:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-24 20:06:27 +0800 |
commit | 94ef428b564f8ba60c2752fb7ca64f804f88baf2 (patch) | |
tree | f18011fc904da78aadd5404046804e152efb6935 /ext/kv/01_db.ts | |
parent | 275dee60e71225a9c6c4b3b4ea7ffe4c6ecb4d87 (diff) |
fix(ext/kv): add missing `getMany` method (#18410)
The `getMany` method was missing from the implementation of the
`Deno.Kv` class. This patch fixes it.
Diffstat (limited to 'ext/kv/01_db.ts')
-rw-r--r-- | ext/kv/01_db.ts | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts index 571a1b3cd..b423a2553 100644 --- a/ext/kv/01_db.ts +++ b/ext/kv/01_db.ts @@ -72,6 +72,36 @@ class Kv { return deserializeValue(entries[0]); } + async getMany( + keys: Deno.KvKey[], + opts?: { consistency?: Deno.KvConsistencyLevel }, + ): Promise<Deno.KvEntry[]> { + keys = keys.map(convertKey); + const ranges: RawKvEntry[][] = await core.opAsync( + "op_kv_snapshot_read", + this.#rid, + keys.map((key) => [ + null, + key, + null, + 1, + false, + null, + ]), + opts?.consistency ?? "strong", + ); + return ranges.map((entries, i) => { + if (!entries.length) { + return { + key: keys[i], + value: null, + versionstamp: null, + }; + } + return deserializeValue(entries[0]); + }); + } + async set(key: Deno.KvKey, value: unknown) { key = convertKey(key); value = serializeValue(value); |