1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

feat(kv): AtomicOperation#sum (#18704)

This commit is contained in:
Ryan Dahl 2023-04-15 10:33:31 +02:00 committed by Levente Kurusa
parent f8d9ba79dd
commit 4e0bfafb24
No known key found for this signature in database
GPG key ID: 9F72F3C05BA137C4
2 changed files with 12 additions and 0 deletions

View file

@ -1827,6 +1827,10 @@ declare namespace Deno {
* for {@linkcode Deno.KvMutation}.
*/
mutate(...mutations: KvMutation[]): this;
/**
* Shortcut for creating a sum mutation.
*/
sum(key: KvKey, n: bigint): this;
/**
* Add to the operation a mutation that sets the value of the specified key
* to the specified value if all checks pass during the commit.

View file

@ -211,6 +211,14 @@ 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;