mirror of
https://github.com/denoland/deno.git
synced 2025-01-07 06:46:59 -05:00
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.
This commit is contained in:
parent
c8f9d89756
commit
9c9bcfe4c9
2 changed files with 40 additions and 0 deletions
|
@ -548,6 +548,16 @@ async function setupData(db: Deno.Kv) {
|
||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbTest("get many", async (db) => {
|
||||||
|
await setupData(db);
|
||||||
|
const entries = await db.getMany([["b", "a"], ["a"], ["c"]]);
|
||||||
|
assertEquals(entries, [
|
||||||
|
{ key: ["b", "a"], value: 100, versionstamp: "00000000000000010000" },
|
||||||
|
{ key: ["a"], value: -1, versionstamp: "00000000000000010000" },
|
||||||
|
{ key: ["c"], value: null, versionstamp: null },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
dbTest("list prefix", async (db) => {
|
dbTest("list prefix", async (db) => {
|
||||||
await setupData(db);
|
await setupData(db);
|
||||||
const entries = await collect(db.list({ prefix: ["a"] }));
|
const entries = await collect(db.list({ prefix: ["a"] }));
|
||||||
|
|
|
@ -72,6 +72,36 @@ class Kv {
|
||||||
return deserializeValue(entries[0]);
|
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) {
|
async set(key: Deno.KvKey, value: unknown) {
|
||||||
key = convertKey(key);
|
key = convertKey(key);
|
||||||
value = serializeValue(value);
|
value = serializeValue(value);
|
||||||
|
|
Loading…
Reference in a new issue