5 The author disclaims copyright to this source code. In place of a
6 legal notice, here is a blessing:
8 * May you do good and not evil.
9 * May you find forgiveness for yourself and forgive others.
10 * May you share freely, never taking more than you give.
12 ***********************************************************************
14 This is a JS Worker file for the main sqlite3 api. It loads
15 sqlite3.js, initializes the module, and postMessage()'s a message
16 after the module is initialized:
18 {type: 'sqlite3-api', result: 'worker1-ready'}
20 This seemingly superfluous level of indirection is necessary when
21 loading sqlite3.js via a Worker. Instantiating a worker with new
22 Worker("sqlite.js") will not (cannot) call sqlite3InitModule() to
23 initialize the module due to a timing/order-of-operations conflict
24 (and that symbol is not exported in a way that a Worker loading it
25 that way can see it). Thus JS code wanting to load the sqlite3
26 Worker-specific API needs to pass _this_ file (or equivalent) to the
27 Worker constructor and then listen for an event in the form shown
28 above in order to know when the module has completed initialization.
30 This file accepts a URL arguments to adjust how it loads sqlite3.js:
32 - `sqlite3.dir`, if set, treats the given directory name as the
33 directory from which `sqlite3.js` will be loaded.
35 //#if target=es6-bundler-friendly
36 import {default as sqlite3InitModule} from './sqlite3-bundler-friendly.mjs';
40 const urlParams = globalThis.location
41 ? new URL(globalThis.location.href).searchParams
42 : new URLSearchParams();
43 let theJs = 'sqlite3.js';
44 if(urlParams.has('sqlite3.dir')){
45 theJs = urlParams.get('sqlite3.dir') + '/' + theJs;
47 //console.warn("worker1 theJs =",theJs);
51 sqlite3InitModule().then(sqlite3 => sqlite3.initWorker1API());
53 /* Built with the omit-oo1 flag. */
54 //#endif ifnot omit-oo1