diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2023-04-26 13:14:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-26 17:14:01 +0000 |
commit | 2df6db36c85c27d424d54e9c168ef4ea09c5c08c (patch) | |
tree | 024397ceb470657f34def26cc938d54af950fb21 /ext/kv/01_db.ts | |
parent | 55a9977c6252a38fac721ad789df0c7e8acf33c9 (diff) |
feat(ext/kv): add more atomic operation helpers (#18854)
Co-authored-by: losfair <zhy20000919@hotmail.com>
Co-authored-by: Luca Casonato <hello@lcas.dev>
Diffstat (limited to 'ext/kv/01_db.ts')
-rw-r--r-- | ext/kv/01_db.ts | 23 |
1 files changed, 15 insertions, 8 deletions
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; |