]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Initial bits for a JS API variant in which the client operates in the main thread...
authorstephan <stephan@noemail.net>
Wed, 1 Jun 2022 00:00:59 +0000 (00:00 +0000)
committerstephan <stephan@noemail.net>
Wed, 1 Jun 2022 00:00:59 +0000 (00:00 +0000)
FossilOrigin-Name: f6d6f969791f0d2367ae5418623b4794f6df657d9d7d9002fb5aec4206dcfd4c

ext/fiddle/sqlite3-api.js
ext/fiddle/sqlite3-worker.js [new file with mode: 0644]
ext/fiddle/testing1.js
ext/fiddle/testing2.html [new file with mode: 0644]
ext/fiddle/testing2.js [new file with mode: 0644]
manifest
manifest.uuid

index d88ec9a8b8694405f33695d9cfd57b3d78444803..e625afc9ba9a14af645542728bba453737df398f 100644 (file)
@@ -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 (file)
index 0000000..6c1e9ca
--- /dev/null
@@ -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');
+    });
+})();
index 9216db13418c48e9f0f3d0445c7e26111d873818..e4afad84eb67a7fa600d3602c7c61efe890c5be1 100644 (file)
@@ -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 (file)
index 0000000..b773c4a
--- /dev/null
@@ -0,0 +1,32 @@
+<!doctype html>
+<html lang="en-us">
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
+    <link rel="stylesheet" href="emscripten.css"/>
+    <link rel="stylesheet" href="testing.css"/>
+    <title>sqlite3-worker.js tests</title>
+    <style></style>
+  </head>
+  <body>
+    <header id='titlebar'><span>sqlite3-worker.js tests</span></header>
+    <!-- emscripten bits -->
+    <figure id="module-spinner">
+      <div class="spinner"></div>
+      <div class='center'><strong>Initializing app...</strong></div>
+      <div class='center'>
+        On a slow internet connection this may take a moment.  If this
+        message displays for "a long time", intialization may have
+        failed and the JavaScript console may contain clues as to why.
+      </div>
+    </figure>
+    <div class="emscripten" id="module-status">Downloading...</div>
+    <div class="emscripten">
+      <progress value="0" max="100" id="module-progress" hidden='1'></progress>  
+    </div><!-- /emscripten bits -->
+    <div>Everything on this page happens in the dev console.</div>
+    <script src="testing-common.js"></script>
+    <script src="testing2.js"></script>
+  </body>
+</html>
diff --git a/ext/fiddle/testing2.js b/ext/fiddle/testing2.js
new file mode 100644 (file)
index 0000000..c258854
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+  2022-05-22
+
+  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.
+
+  ***********************************************************************
+
+  A basic test script for sqlite3-worker.js.
+*/
+(function(){
+    /** Posts a worker message as {type:type, data:data}. */
+    const SW = new Worker("sqlite3-worker.js");
+    const wMsg = (type,data)=>SW.postMessage({type, data});
+    const log = console.log.bind(console);
+    const warn = console.warn.bind(console);
+    SW.onmessage = function(ev){
+        if(!ev.data || 'object'!==typeof ev.data){
+            warn("Unknown sqlite3-worker message type:",ev);
+            return;
+        }
+        ev = ev.data/*expecting a nested object*/;
+        switch(ev.type){
+            case 'sqlite3-api':
+                switch(ev.data){
+                    case 'loaded':
+                        log("Message:",ev); return;
+                    case 'ready':
+                        log("Message:",ev);
+                        self.sqlite3TestModule.setStatus(null);
+                        return;
+                    default: break;
+                }
+                break;
+        }
+        warn("Unknown sqlite3-api message type:",ev);
+    };
+    log("Init complete, but async bits may still be running.");
+})();
index 591efee1446c18729d66a2f173b6dff87cc1bc35..4f9ee1b8f171ac4080f54d76db5464bcce877823 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C New\sFULL\sJOIN\stest\scases.\s\sNo\schanges\sto\scode.
-D 2022-05-31T18:18:09.648
+C Initial\sbits\sfor\sa\sJS\sAPI\svariant\sin\swhich\sthe\sclient\soperates\sin\sthe\smain\sthread\sand\ssqlite3\sin\sa\sWorker.\sThis\sis\sfar\sfrom\scomplete.
+D 2022-06-01T00:00:59.491
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -65,10 +65,13 @@ F ext/fiddle/fiddle-worker.js 3a19253dc026d1ad9064ee853f3c4da3385223ce4434dab183
 F ext/fiddle/fiddle.html 724f1cd4126616bc87f5871f78d3f7aaaf41e45c9728724627baab87e6af35f0
 F ext/fiddle/fiddle.js 5b456ed7085830cda2fc75a0801476174a978521949335f24bc4154d076dcd4d
 F ext/fiddle/index.md d9c1c308d8074341bc3b11d1d39073cd77754cb3ca9aeb949f23fdd8323d81cf
-F ext/fiddle/sqlite3-api.js 8500698d2163f4a25f8e5e6810ad826487342579d6a321d82b244dbc8e6f6db6
+F ext/fiddle/sqlite3-api.js ff9580cf075c08bd124ad057079bd32fd121f1e122c8c40e3a836466c1fe1197
+F ext/fiddle/sqlite3-worker.js c137daed6529b5f527ed61eb358cb0d23f90e04784442479cd15ac684eccdf7a
 F ext/fiddle/testing.css 750572dded671d2cf142bbcb27af5542522ac08db128245d0b9fe410aa1d7f2a
 F ext/fiddle/testing1.html ea1f3be727f78e420007f823912c1a03b337ecbb8e79449abc2244ad4fe15d9a
-F ext/fiddle/testing1.js 94a7597955c8fdbd15839a70d9b8279bc690205dda65ff175f688f13bf315745
+F ext/fiddle/testing1.js e09c224da12b34bd90a1128d4a9cfc546ccca00074d00571977eb44746bf487d
+F ext/fiddle/testing2.html 9063b2430ade2fe9da4e711addd1b51a2741cf0c7ebf6926472a5e5dd63c0bc4
+F ext/fiddle/testing2.js 0382f20c6c5e1b2a034240a29d627f0e6ccb9c3be50d7dd1627b04ad5f92b787
 F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
 F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b
 F ext/fts1/ft_hash.h 06df7bba40dadd19597aa400a875dbc2fed705ea
@@ -1971,8 +1974,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P f2d224c5fa06de70f6f22e159a3b7065d4c6b004f9accc13004b9ac1f2fd5549
-R 5689511af50987f5a7f98a74e3792280
-U drh
-Z cf62f2b6249a650ef9ed77273d324cc2
+P 13e89ef6649475815d3f4e4aef73a4be1157dd388e55c7f856faeb4b7387774b
+R 1d9b814402b0908178d5c21bd5502d71
+U stephan
+Z f7d167c241a574fa46d16e96c1270f84
 # Remove this line to create a well-formed Fossil manifest.
index 04e5adb2bd658c7cc5e43a1ac46621dbf00c816e..d352df1b8e4539ff9360b8056b5e9a8ddc83665f 100644 (file)
@@ -1 +1 @@
-13e89ef6649475815d3f4e4aef73a4be1157dd388e55c7f856faeb4b7387774b
\ No newline at end of file
+f6d6f969791f0d2367ae5418623b4794f6df657d9d7d9002fb5aec4206dcfd4c
\ No newline at end of file