aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-worker1.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-08-24 20:57:37 +0000
committerstephan <stephan@noemail.net>2022-08-24 20:57:37 +0000
commit407f75378e2bfebfd21ca56b6986154f0c35d1ac (patch)
treec22591d4e185d9717feaa985d49ae1cd64095950 /ext/wasm/api/sqlite3-api-worker1.js
parent3734401a95dc92f7cb7c3a86875370f1598213aa (diff)
downloadsqlite-407f75378e2bfebfd21ca56b6986154f0c35d1ac.tar.gz
sqlite-407f75378e2bfebfd21ca56b6986154f0c35d1ac.zip
Change DB.exec() rowMode default from 'stmt' to 'array', per /chat discussion. Add DB.exec() rowMode option for fetching a specific column by name. Add result column names to worker1 exec() callback interface, as there's otherwise no way to get that info from a worker.
FossilOrigin-Name: 1bb37e5c477b9eb098362f74a45a55be23d450fe45cdff58c1cbff08b5b3998f
Diffstat (limited to 'ext/wasm/api/sqlite3-api-worker1.js')
-rw-r--r--ext/wasm/api/sqlite3-api-worker1.js46
1 files changed, 30 insertions, 16 deletions
diff --git a/ext/wasm/api/sqlite3-api-worker1.js b/ext/wasm/api/sqlite3-api-worker1.js
index afb2e7812..90c8f0de1 100644
--- a/ext/wasm/api/sqlite3-api-worker1.js
+++ b/ext/wasm/api/sqlite3-api-worker1.js
@@ -249,7 +249,11 @@ sqlite3.initWorker1API = function(){
message type key, in which case a callback function will be
applied which posts each row result via:
- postMessage({type: thatKeyType, rowNumber: 1-based-#, row: theRow})
+ postMessage({type: thatKeyType,
+ rowNumber: 1-based-#,
+ row: theRow,
+ columnNames: anArray
+ })
And, at the end of the result set (whether or not any result
rows were produced), it will post an identical message with
@@ -280,12 +284,7 @@ sqlite3.initWorker1API = function(){
const rc = (
'string'===typeof ev.args
) ? {sql: ev.args} : (ev.args || Object.create(null));
- if(undefined===rc.rowMode){
- /* Since the default rowMode of 'stmt' is not useful
- for the Worker interface, we'll default to
- something else. */
- rc.rowMode = 'array';
- }else if('stmt'===rc.rowMode){
+ if('stmt'===rc.rowMode){
toss("Invalid rowMode for 'exec': stmt mode",
"does not work in the Worker API.");
}
@@ -294,25 +293,40 @@ sqlite3.initWorker1API = function(){
// Part of a copy-avoidance optimization for blobs
db._blobXfer = wState.xfer;
}
- const callbackMsgType = rc.callback;
+ const theCallback = rc.callback;
let rowNumber = 0;
- if('string' === typeof callbackMsgType){
+ const hadColNames = !!rc.columnNames;
+ if('string' === typeof theCallback){
+ if(!hadColNames) rc.columnNames = [];
/* Treat this as a worker message type and post each
row as a message of that type. */
- rc.callback =
- (row)=>wState.post({type: callbackMsgType, rowNumber:++rowNumber, row:row}, wState.xfer);
+ rc.callback = function(row,stmt){
+ wState.post({
+ type: theCallback,
+ columnNames: rc.columnNames,
+ rowNumber: ++rowNumber,
+ row: row
+ }, wState.xfer);
+ }
}
try {
db.exec(rc);
if(rc.callback instanceof Function){
- rc.callback = callbackMsgType;
- wState.post({type: callbackMsgType, rowNumber: null, row: undefined});
+ rc.callback = theCallback;
+ /* Post a sentinel message to tell the client that the end
+ of the result set has been reached (possibly with zero
+ rows). */
+ wState.post({
+ type: theCallback,
+ columnNames: rc.columnNames,
+ rowNumber: null /*null to distinguish from "property not set"*/,
+ row: undefined /*undefined because null is a legal row value
+ for some rowType values, but undefined is not*/
+ });
}
}finally{
delete db._blobXfer;
- if(rc.callback){
- rc.callback = callbackMsgType;
- }
+ if(rc.callback) rc.callback = theCallback;
}
return rc;
}/*exec()*/,