Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kv): AtomicOperation#sum #18704

Merged
merged 3 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/tsc/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,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.
Expand Down
8 changes: 8 additions & 0 deletions ext/kv/01_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down