Querying stores, working with blobs, utilities for keys, batched atomic transactions, encrypting values, and more.
@deno/kv-utils
adopts core kv-toolbox
capabilities.JSON serialization, NDJSON import/export, and estimating the size of entries are now part of the official Deno KV utilities library.
Check it outopenKvToolbox()
allow access to most of the features of the library in an enriched that builds on top of Deno.Kv
.
import { openKvToolbox } from "@kitsonk/kv-toolbox";
const file = await Deno.readFile("hello.jpeg");
const kv = await openKvToolbox();
await kv.setBlob(["hello.jpeg"], file);
kv.close();
import {
query,
Filter
} from "@kitsonk/kv-toolbox/query";
const db = await Deno.openKv();
const result = query(db, { prefix: [] })
.where(Filter.or(
Filter.where("age", "<", 10),
Filter.where("age", ">", 20),
))
.get();
for await (const entry of result) {
console.log(entry);
}
db.close();
A fluent API for querying Deno KV stores, including deep queries into values of entries.
See the docsWorking with arbitrarily size blobs like Uint8Array
s, byte ReadableStream
s, Blob
s and File
s, stream blob values to a browser, and manage Deno KV's 64k per entry value limit.
import {
get,
getAsBlob,
getAsJSON,
getAsResponse,
getAsStream,
getMeta,
remove,
set,
toJSON,
toValue,
} from "@kitsonk/kv-toolbox/blob";
import {
equals,
keys,
partEquals,
startsWith,
tree,
unique,
uniqueCount,
} from "@kitsonk/kv-toolbox/keys";
Make working with Deno KV keys easier, especially when using a sub-key pattern.
See the docsCreate atomic transactions without having to worry about Deno KV's limitations per transaction as well as provide atomic transactions for blobs via .checkBlob()
and .setBlob()
.
import {
batchedAtomic,
} from "@kitsonk/kv-toolbox/batched_atomic";
const kv = await Deno.openKv();
await batchedAtomic(kv)
.check({ key: ["hello"], versionstamp: null })
.checkBlob({ key: ["video"], versionstamp: null })
.set(["hello"], "deno kv")
.setBlob(
["video"],
new Blob([], { type: "video/mp4" }),
)
.commit();
await kv.close();
import {
generateKey,
openCryptoKv,
} from "@kitsonk/kv-toolbox/crypto";
const kv = await openCryptoKv(generateKey());
const res = await kv.setBlob(
["hello"],
window.crypto.getRandomValues(new Uint8Array(65_536)),
);
if (res.ok) {
const maybeValue = await kv.getBlob(["hello"]);
await kv.deleteBlob(["hello"]);
}
kv.close();
Encrypt and decrypt Deno KV values, ensuring that data at rest is secure.
See the docs