mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
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.
This commit is contained in:
parent
206c593519
commit
e888c3f534
7 changed files with 137 additions and 112 deletions
|
@ -17,6 +17,7 @@ use rusqlite::OptionalExtension;
|
|||
use rusqlite::Transaction;
|
||||
|
||||
use crate::AtomicWrite;
|
||||
use crate::CommitResult;
|
||||
use crate::Database;
|
||||
use crate::DatabaseHandler;
|
||||
use crate::KvEntry;
|
||||
|
@ -216,7 +217,10 @@ impl Database for SqliteDb {
|
|||
Ok(responses)
|
||||
}
|
||||
|
||||
async fn atomic_write(&self, write: AtomicWrite) -> Result<bool, AnyError> {
|
||||
async fn atomic_write(
|
||||
&self,
|
||||
write: AtomicWrite,
|
||||
) -> Result<Option<CommitResult>, AnyError> {
|
||||
let mut db = self.0.borrow_mut();
|
||||
|
||||
let tx = db.transaction()?;
|
||||
|
@ -228,7 +232,7 @@ impl Database for SqliteDb {
|
|||
.optional()?
|
||||
.map(version_to_versionstamp);
|
||||
if real_versionstamp != check.versionstamp {
|
||||
return Ok(false);
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,7 +277,11 @@ impl Database for SqliteDb {
|
|||
|
||||
tx.commit()?;
|
||||
|
||||
Ok(true)
|
||||
let new_vesionstamp = version_to_versionstamp(version);
|
||||
|
||||
Ok(Some(CommitResult {
|
||||
versionstamp: new_vesionstamp,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue