aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-worker1.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2023-05-25 16:49:06 +0000
committerstephan <stephan@noemail.net>2023-05-25 16:49:06 +0000
commit39bd6a0d46ea03ae374e57dc2898b9476e15a8f1 (patch)
tree0e58b901ce828c1332de7baec6314550b58b1a51 /ext/wasm/api/sqlite3-api-worker1.js
parent4e8e33ba84e253878797d7f4443810387cb87469 (diff)
downloadsqlite-39bd6a0d46ea03ae374e57dc2898b9476e15a8f1.tar.gz
sqlite-39bd6a0d46ea03ae374e57dc2898b9476e15a8f1.zip
Add ability for the JS Worker1.exec() API to report the number of changes made to the caller, per request in [forum:d0b19483642e20dd | forum post d0b19483642e20dd].
FossilOrigin-Name: 6e79505df915612b60696e4eec5c9973175fe6ecf273eb3152b996e63ae54a07
Diffstat (limited to 'ext/wasm/api/sqlite3-api-worker1.js')
-rw-r--r--ext/wasm/api/sqlite3-api-worker1.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/wasm/api/sqlite3-api-worker1.js b/ext/wasm/api/sqlite3-api-worker1.js
index d1c63c96e..9a386c13e 100644
--- a/ext/wasm/api/sqlite3-api-worker1.js
+++ b/ext/wasm/api/sqlite3-api-worker1.js
@@ -278,6 +278,19 @@
The arguments are in the same form accepted by oo1.DB.exec(), with
the exceptions noted below.
+ If the `countChanges` arguments property (added in version 3.43) is
+ truthy then the `result` property contained by the returned object
+ will have a `changeCount` property which holds the number of changes
+ made by the provided SQL. Because the SQL may contain an arbitrary
+ number of statements, the `changeCount` is calculated by calling
+ `sqlite3_total_changes()` before and after the SQL is evaluated. If
+ the value of `countChanges` is 64 then the `changeCount` property
+ will be returned as a 64-bit integer in the form of a BigInt (noting
+ that that will trigger an exception if used in a BigInt-incapable
+ build). In the latter case, the number of changes is calculated by
+ calling `sqlite3_total_changes64()` before and after the SQL is
+ evaluated.
+
A function-type args.callback property cannot cross
the window/Worker boundary, so is not useful here. If
args.callback is a string then it is assumed to be a
@@ -523,7 +536,13 @@ sqlite3.initWorker1API = function(){
}
}
try {
+ const changeCount = !!rc.countChanges
+ ? db.changes(true,(64===rc.countChanges))
+ : undefined;
db.exec(rc);
+ if(undefined !== changeCount){
+ rc.changeCount = db.changes(true,64===rc.countChanges) - changeCount;
+ }
if(rc.callback instanceof Function){
rc.callback = theCallback;
/* Post a sentinel message to tell the client that the end