Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/kv_toolbox/batched_atomic.ts

Utilities for working with Deno KV 🦕🗝️
Go to Latest
import * as kvToolbox from "https://deno.land/x/kv_toolbox@0.16.2/batched_atomic.ts";

Provides the function batchedAtomic which is like Deno.Kv.prototype.atomic but will work around the per atomic transaction limits imposed by Deno KV.

It also supports setBlob() and checkBlob() to allow setting of checking of kv-toolbox blob values as part of a transaction.

In the past, Deno KV had very low limits (like 10 mutations per transaction) but those limits have been changed to far more reasonable levels, so in most cases batchedAtomic is not needed. The only advantage is that you can make arbitrarily large atomic transactions and not worry about having to deal with a limit failure in code. But most users should consider just dealing with Deno.Kv.prototype.atomic directly.

Examples

Example 1

import { batchedAtomic } from "jsr:/@kitsonk/kv-toolbox/batched_atomic";

const kv = await Deno.openKv();
await batchedAtomic(kv)
  .check({ key: ["hello"], versionstamp: null })
  .set(["hello"], "deno kv")
  .commit();
await kv.close();

Classes

The class that encapsulates the batched atomic operations. Works around limitations imposed by Deno KV related to individual atomic operations.

Functions

Similar to Deno.Kv.prototype.atomic but deals with the limits of transactions imposed by Deno KV.

Interfaces

Options which can be adjusted when using a batched atomic.