diff --git a/ext/fiddle/sqlite3-api.js b/ext/fiddle/sqlite3-api.js index d88ec9a8b8..e625afc9ba 100644 --- a/ext/fiddle/sqlite3-api.js +++ b/ext/fiddle/sqlite3-api.js @@ -85,7 +85,8 @@ if(!Module.postRun) Module.postRun = []; /* ^^^^ the name Module is, in this setup, scope-local in the generated file sqlite3.js, with which this file gets combined at build-time. */ -Module.postRun.push(function(namespace){ +Module.postRun.push(function(namespace/*the module object, the target for + installed features*/){ 'use strict'; /* For reference: sql.js does essentially everything we want and it solves much of the wasm-related voodoo, but we'll need a @@ -470,7 +471,7 @@ Module.postRun.push(function(namespace){ execMulti(): - .multi: if true, this function acts as a proxy for - execMulti(). + execMulti() and behaves identically to that function. */ exec: function(/*(sql [,optionsObj]) or (optionsObj)*/){ affirmDbOpen(this); @@ -549,13 +550,15 @@ Module.postRun.push(function(namespace){ ACHTUNG #1: The callback MUST NOT modify the Stmt object. Calling any of the Stmt.get() variants, - Stmt.getColumnName(), or simililar, is legal, but calling + Stmt.getColumnName(), or similar, is legal, but calling step() or finalize() is not. Routines which are illegal in this context will trigger an exception. ACHTUNG #2: The semantics of the `bind` and `callback` options may well change or those options may be removed altogether for this function (but retained for exec()). + Generally speaking, neither bind parameters nor a callback + are generically useful when executing multi-statement SQL. */ execMulti: function(/*(sql [,obj]) || (obj)*/){ affirmDbOpen(this); @@ -1327,8 +1330,8 @@ Module.postRun.push(function(namespace){ DB, Stmt, /** - Reports whether a given compile-time option, named by the - given argument. It has several distinct uses: + Reports info about compile-time options. It has several + distinct uses: If optName is an array then it is expected to be a list of compilation options and this function returns an object @@ -1387,10 +1390,41 @@ Module.postRun.push(function(namespace){ 'string'===typeof optName ) ? !!api.sqlite3_compileoption_used(optName) : false; } - }; + }/*SQLite3 object*/; namespace.sqlite3 = { api: api, SQLite3 }; + + if(self === self.window){ + /* This is running in the main window thread, so we're done. */ + return; + } + /****************************************************************** + End of main window thread. What follows is only intended for use + in Worker threads. + ******************************************************************/ + + /* + TODO: we need an API which can proxy the DB API via a Worker + message interface. The primary quirky factor in such an API is + that clients cannot pass callback functions to it, so have to receive + all query results via asynchronous message-passing. + + Certain important considerations here include: + + - Support only one db connectior or multiple? The former is far + easier, but there's always going to be a user out there who + wants to juggle six database handles at once. + + - Fetching multiple results: do we pass them on as a series of + messages, with start/end messages on either end, or do we + collect all results and bundle them back in a single message? + The former is, generically speaking, more memory-efficient but + the latter far easier to implement in this environment. + */ + + + setTimeout(()=>postMessage({type:'sqlite3-api',data:'loaded'}), 0); }); diff --git a/ext/fiddle/sqlite3-worker.js b/ext/fiddle/sqlite3-worker.js new file mode 100644 index 0000000000..6c1e9ca672 --- /dev/null +++ b/ext/fiddle/sqlite3-worker.js @@ -0,0 +1,35 @@ +/* + 2022-05-23 + + The author disclaims copyright to this source code. In place of a + legal notice, here is a blessing: + + * May you do good and not evil. + * May you find forgiveness for yourself and forgive others. + * May you share freely, never taking more than you give. + + *********************************************************************** + + UNDER CONSTRUCTION + + This is a JS Worker file for the main sqlite3 api. It loads + sqlite3.js and offers access to the db via the Worker + message-passing interface. +*/ + +"use strict"; +(function(){ + /** Posts a worker message as {type:type, data:data}. */ + const wMsg = (type,data)=>self.postMessage({type, data}); + self.onmessage = function(ev){ + /*ev = ev.data; + switch(ev.type){ + default: break; + };*/ + console.warn("Unknown sqlite3-worker message type:",ev); + }; + importScripts('sqlite3.js'); + initSqlite3Module().then(function(){ + wMsg('sqlite3-api','ready'); + }); +})(); diff --git a/ext/fiddle/testing1.js b/ext/fiddle/testing1.js index 9216db1341..e4afad84eb 100644 --- a/ext/fiddle/testing1.js +++ b/ext/fiddle/testing1.js @@ -10,7 +10,8 @@ *********************************************************************** - A basic test script for sqlite3-api.js. + A basic test script for sqlite3-api.js. This file must be run in + main JS thread and sqlite3.js must have been loaded before it. */ (function(){ const T = self.SqliteTestUtil; diff --git a/ext/fiddle/testing2.html b/ext/fiddle/testing2.html new file mode 100644 index 0000000000..b773c4aa48 --- /dev/null +++ b/ext/fiddle/testing2.html @@ -0,0 +1,32 @@ + + +
+ + + + + +