From 2df6db36c85c27d424d54e9c168ef4ea09c5c08c Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 26 Apr 2023 13:14:01 -0400 Subject: feat(ext/kv): add more atomic operation helpers (#18854) Co-authored-by: losfair Co-authored-by: Luca Casonato --- ext/kv/01_db.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'ext') diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts index 1a7b27dac..da29a0952 100644 --- a/ext/kv/01_db.ts +++ b/ext/kv/01_db.ts @@ -211,14 +211,6 @@ class AtomicOperation { return this; } - sum(key: Deno.KvKey, n: bigint): this { - return this.mutate({ - type: "sum", - key, - value: new KvU64(n), - }); - } - mutate(...mutations: Deno.KvMutation[]): this { for (const mutation of mutations) { const key = mutation.key; @@ -249,6 +241,21 @@ class AtomicOperation { return this; } + sum(key: Deno.KvKey, n: bigint): this { + this.#mutations.push([key, "sum", serializeValue(new KvU64(n))]); + return this; + } + + min(key: Deno.KvKey, n: bigint): this { + this.#mutations.push([key, "min", serializeValue(new KvU64(n))]); + return this; + } + + max(key: Deno.KvKey, n: bigint): this { + this.#mutations.push([key, "max", serializeValue(new KvU64(n))]); + return this; + } + set(key: Deno.KvKey, value: unknown): this { this.#mutations.push([key, "set", serializeValue(value)]); return this; -- cgit v1.2.3