Deno's KV Store
1 min read
Deno’s KV database (Key Value) certainly gives me a bit of a warm nostalgic feeling for M Globals.
const eaKv = await Deno.openKv("./EA");
const paddedId = " 917";
const EMP = "EMPLOYEE";
await eaKv.set([EMP, paddedId], "Aaron");
await eaKv.set([EMP, " 0234"], "JRR Tolkien");
await eaKv.set([EMP, " 51"], "Agatha Christie");
const aaron = await eaKv.get([EMP, paddedId]);
console.log(`Data for ${paddedId}`, aaron);
console.log("-------------------------------------------");
console.log("All employees, $ORDER ANYONE?");
for await (const res of eaKv.list({ prefix: [EMP] })) {
console.log(res);
}
It’s beta so you need to add a command-line flag to enable the functionality:
> deno run -A --unstable-kv main.ts
Results …
Data for 917 {
key: [ "EMPLOYEE", " 917" ],
value: "Aaron",
versionstamp: "000000000000004b0000"
}
-------------------------------------------
All Employees, $ORDER ANYONE?
{
key: [ "EMPLOYEE", " 51" ],
value: "Agatha Christie",
versionstamp: "00000000000000570000"
}
{
key: [ "EMPLOYEE", " 917" ],
value: "Aaron",
versionstamp: "000000000000004b0000"
}
{
key: [ "EMPLOYEE", " 0234" ],
value: "JRR Tolkien",
versionstamp: "00000000000000500000"
}
There’s a local version that runs within the Deno runtime and backed by a Sqlite database.
Windows Install
You can install Deno in Windows with winget
:
winget install deno