aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-worker1.c-pp.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2025-02-09 02:41:35 +0000
committerstephan <stephan@noemail.net>2025-02-09 02:41:35 +0000
commitf85818268965207d7682438132d51195d4e28bf0 (patch)
treed53fa71a928e5f96477f25aced39d8f314f1a57c /ext/wasm/api/sqlite3-api-worker1.c-pp.js
parent3e06f2d79b15754999892a4ded6a7585520294a6 (diff)
downloadsqlite-f85818268965207d7682438132d51195d4e28bf0.tar.gz
sqlite-f85818268965207d7682438132d51195d4e28bf0.zip
JS: add a mechanism to the Worker1 exec API to fetch the last_insert_rowid(), as requested in [forum:56bc35390183f5d5|forum post 56bc353901].
FossilOrigin-Name: c22c48360756b1c7e2f5a9c01aff799bc188e100d364931de0dc3686e5de57a9
Diffstat (limited to 'ext/wasm/api/sqlite3-api-worker1.c-pp.js')
-rw-r--r--ext/wasm/api/sqlite3-api-worker1.c-pp.js25
1 files changed, 20 insertions, 5 deletions
diff --git a/ext/wasm/api/sqlite3-api-worker1.c-pp.js b/ext/wasm/api/sqlite3-api-worker1.c-pp.js
index 991862545..5e088f438 100644
--- a/ext/wasm/api/sqlite3-api-worker1.c-pp.js
+++ b/ext/wasm/api/sqlite3-api-worker1.c-pp.js
@@ -279,11 +279,11 @@
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
+ If `args.countChanges` (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
@@ -292,6 +292,15 @@
calling `sqlite3_total_changes64()` before and after the SQL is
evaluated.
+ If the `args.lastInsertRowId` (added in version 3.50.0) is truthy
+ then the `result` property contained by the returned object will
+ have a `lastInsertRowId` will hold a BigInt-type value corresponding
+ to the result of sqlite3_last_insert_rowid(). This value is only
+ fetched once, after the SQL is run, regardless of how many
+ statements the SQL contains. This API has no idea whether the SQL
+ contains any INSERTs, so it is up to the client to apply/rely on
+ this property only when it makes sense to do so.
+
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
@@ -542,6 +551,12 @@ sqlite3.initWorker1API = function(){
if(undefined !== changeCount){
rc.changeCount = db.changes(true,64===rc.countChanges) - changeCount;
}
+ const lastInsertRowId = !!rc.lastInsertRowId
+ ? sqlite3.capi.sqlite3_last_insert_rowid(db)
+ : undefined;
+ if( undefined!==lastInsertRowId ){
+ rc.lastInsertRowId = lastInsertRowId;
+ }
if(rc.callback instanceof Function){
rc.callback = theCallback;
/* Post a sentinel message to tell the client that the end