You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
566 B

#!/usr/bin/env deno run --unstable-kv --allow-read --allow-write
// deno-lint-ignore-file prefer-const
import { parseArgs } from "jsr:@std/cli";
let db = await Deno.openKv("incrementer");
if (import.meta.main) {
let args = parseArgs(Deno.args);
let ns = args["_"][0] ?? "_global";
let old = await db.get([ns]);
let nextVal = old.value + 1;
let n = await db.atomic()
.check(old)
.set([ns], nextVal)
.commit();
if (n.ok === false) {
console.error("failed to commit result to Deno KV");
Deno.exit(1);
}
console.log(nextVal);
}