-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-many.ts
More file actions
41 lines (34 loc) · 1.12 KB
/
Copy pathget-many.ts
File metadata and controls
41 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Using `getMany()` to retrieve all environmental variables stored in separate indexes in a single call.
*/
import { assert } from "https://deno.land/std@0.153.0/testing/asserts.ts";
import { deleteAllRecords } from "./util.ts";
await deleteAllRecords();
const kv = await Deno.openKv();
// keys
const githubSecretKey = ["env_var", "GITHUB_ACCESS_KEY"];
const googleSecretKey = ["env_var", "GOOGLE_ACCESS_KEY"];
const discordSecretKey: Deno.KvKey = ["env_var", "DISCORD_ACCESS_KEY"];
// store env vars in separate indexes
await kv.set(discordSecretKey, "password1");
await kv.set(githubSecretKey, "password2");
await kv.set(googleSecretKey, "password3");
// get all env var entries in one call
const envVars = await kv.getMany([
githubSecretKey,
googleSecretKey,
discordSecretKey,
]);
console.log(envVars);
assert(
envVars[0].key[1] === githubSecretKey[1],
"Github key does not match expected key value",
);
assert(
envVars[1].key[1] === googleSecretKey[1],
"Google key does not match expected key value",
);
assert(
envVars[2].key[1] === discordSecretKey[1],
"Discord key does not match expected key value",
);