diff options
author | Luca Casonato <hello@lcas.dev> | 2023-03-30 20:57:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-30 20:57:21 +0200 |
commit | e888c3f534c6ce9574f1d57e5cc61573a046039e (patch) | |
tree | 3bb52d77e111142c372826bb2cfd38f49da90ef1 /ext/kv/01_db.ts | |
parent | 206c593519681a024409d9dd23ef55b1d13d938f (diff) |
feat(ext/kv): return versionstamp from set/commit (#18512)
This commit updates the `Deno.Kv` API to return the new commited
versionstamp for the mutated data from `db.set` and `ao.commit`. This is
returned in the form of a `Deno.KvCommitResult` object that has a
`versionstamp` property.
Diffstat (limited to 'ext/kv/01_db.ts')
-rw-r--r-- | ext/kv/01_db.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts index 70e4c7fca..e0c5335e6 100644 --- a/ext/kv/01_db.ts +++ b/ext/kv/01_db.ts @@ -111,14 +111,15 @@ class Kv { [key, "set", value], ]; - const result = await core.opAsync( + const versionstamp = await core.opAsync( "op_kv_atomic_write", this.#rid, checks, mutations, [], ); - if (!result) throw new TypeError("Failed to set value"); + if (versionstamp === null) throw new TypeError("Failed to set value"); + return { versionstamp }; } async delete(key: Deno.KvKey) { @@ -255,15 +256,16 @@ class AtomicOperation { return this; } - async commit(): Promise<boolean> { - const result = await core.opAsync( + async commit(): Promise<Deno.KvCommitResult | null> { + const versionstamp = await core.opAsync( "op_kv_atomic_write", this.#rid, this.#checks, this.#mutations, [], // TODO(@losfair): enqueue ); - return result; + if (versionstamp === null) return null; + return { versionstamp }; } then() { |