getDenoKv(store: ,key: StorageKey,): Promise<Deno.Kv | undefined>
Utility to attempt to get the underlying Deno.Kv
if the store is backed by it.
▶Example 1
Example 1
import { getDenoKv } from "jsr:@jollytoad/store-deno-kv/get-deno-kv"; import * as store from "jsr:@jollytoad/store"; // Set the delegate store, try changing this to "jsr:@jollytoad/store-deno-fs" store.setStore(import("jsr:@jollytoad/store-deno-kv")); const kv = await getDenoKv(store, ["foo"]); const key = ["foo", "counter"]; if (kv) { // we can do an atomic increment... kv.atomic() .mutate({ type: "sum", key, value: new Deno.KvU64(1n) }) .commit(); } else { // otherwise fallback to a risky, get and set... await store.setItem(key, (await store.getItem<number>(key) ?? 0) + 1); }
key: StorageKey