aboutsummaryrefslogtreecommitdiff
path: root/ext/fiddle/sqlite3-api.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-06-01 00:00:59 +0000
committerstephan <stephan@noemail.net>2022-06-01 00:00:59 +0000
commitbff17db433d1b0240a9e40a7f33e7a873f9cec71 (patch)
tree7a52d6de1dfaf8b806c744245a060b7e52e367f5 /ext/fiddle/sqlite3-api.js
parentc7fc08f69accd7bb3753477df503660ecacf2e81 (diff)
downloadsqlite-bff17db433d1b0240a9e40a7f33e7a873f9cec71.tar.gz
sqlite-bff17db433d1b0240a9e40a7f33e7a873f9cec71.zip
Initial bits for a JS API variant in which the client operates in the main thread and sqlite3 in a Worker. This is far from complete.
FossilOrigin-Name: f6d6f969791f0d2367ae5418623b4794f6df657d9d7d9002fb5aec4206dcfd4c
Diffstat (limited to 'ext/fiddle/sqlite3-api.js')
-rw-r--r--ext/fiddle/sqlite3-api.js46
1 files changed, 40 insertions, 6 deletions
diff --git a/ext/fiddle/sqlite3-api.js b/ext/fiddle/sqlite3-api.js
index d88ec9a8b..e625afc9b 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);
});