Skip to main content

Built and signed on GitHub Actions

Deno KV Storage Module

This package works with Deno
This package works with Deno
JSR Score
94%
Published
2 months ago (0.4.0)
function getDenoKv
getDenoKv(
store: ,
): Promise<Deno.Kv | undefined>

Utility to attempt to get the underlying Deno.Kv if the store is backed by it.

Examples

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);
}

Parameters

Return Type

Promise<Deno.Kv | undefined>

Add Package

deno add jsr:@jollytoad/store-deno-kv

Import symbol

import { getDenoKv } from "@jollytoad/store-deno-kv/get-deno-kv";

---- OR ----

Import directly with a jsr specifier

import { getDenoKv } from "jsr:@jollytoad/store-deno-kv/get-deno-kv";