4 The author disclaims copyright to this source code. In place of a
5 legal notice, here is a blessing:
7 * May you do good and not evil.
8 * May you find forgiveness for yourself and forgive others.
9 * May you share freely, never taking more than you give.
11 ***********************************************************************
13 This is a JS Worker file for the main sqlite3 api. It loads
14 sqlite3.js, initializes the module, and postMessage()'s a message
15 after the module is initialized:
17 {type: 'sqlite3-api', result: 'worker1-ready'}
19 This seemingly superfluous level of indirection is necessary when
20 loading sqlite3.js via a Worker. Instantiating a worker with new
21 Worker("sqlite.js") will not (cannot) call sqlite3InitModule() to
22 initialize the module due to a timing/order-of-operations conflict
23 (and that symbol is not exported in a way that a Worker loading it
24 that way can see it). Thus JS code wanting to load the sqlite3
25 Worker-specific API needs to pass _this_ file (or equivalent) to the
26 Worker constructor and then listen for an event in the form shown
27 above in order to know when the module has completed initialization.
29 This file accepts a URL arguments to adjust how it loads sqlite3.js:
31 - `sqlite3.dir`, if set, treats the given directory name as the
32 directory from which `sqlite3.js` will be loaded.
36 const urlParams
= new URL(self
.location
.href
).searchParams
;
37 let theJs
= 'sqlite3.js';
38 if(urlParams
.has('sqlite3.dir')){
39 theJs
= urlParams
.get('sqlite3.dir') + '/' + theJs
;
41 //console.warn("worker1 theJs =",theJs);
43 sqlite3InitModule().then((sqlite3
)=>{
44 if(sqlite3
.capi
.sqlite3_wasmfs_opfs_dir
){
45 sqlite3
.capi
.sqlite3_wasmfs_opfs_dir();
47 sqlite3
.initWorker1API();