2022-08-10 14:26:08 +03:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
|
|
|
|
***********************************************************************
|
|
|
|
|
|
|
|
This is a JS Worker file for the main sqlite3 api. It loads
|
|
|
|
sqlite3.js, initializes the module, and postMessage()'s a message
|
|
|
|
after the module is initialized:
|
|
|
|
|
2022-08-24 03:10:45 +03:00
|
|
|
{type: 'sqlite3-api', result: 'worker1-ready'}
|
2022-08-10 14:26:08 +03:00
|
|
|
|
|
|
|
This seemingly superfluous level of indirection is necessary when
|
|
|
|
loading sqlite3.js via a Worker. Instantiating a worker with new
|
|
|
|
Worker("sqlite.js") will not (cannot) call sqlite3InitModule() to
|
|
|
|
initialize the module due to a timing/order-of-operations conflict
|
|
|
|
(and that symbol is not exported in a way that a Worker loading it
|
|
|
|
that way can see it). Thus JS code wanting to load the sqlite3
|
|
|
|
Worker-specific API needs to pass _this_ file (or equivalent) to the
|
|
|
|
Worker constructor and then listen for an event in the form shown
|
|
|
|
above in order to know when the module has completed initialization.
|
|
|
|
*/
|
|
|
|
"use strict";
|
2022-10-01 16:38:27 +03:00
|
|
|
(()=>{
|
|
|
|
const urlParams = new URL(self.location.href).searchParams;
|
|
|
|
importScripts(urlParams.has('wasmfs')
|
|
|
|
? 'sqlite3-wasmfs.js'
|
|
|
|
: 'sqlite3.js');
|
|
|
|
sqlite3InitModule().then((sqlite3)=>{
|
|
|
|
sqlite3.capi.sqlite3_wasmfs_opfs_dir();
|
|
|
|
sqlite3.initWorker1API();
|
|
|
|
});
|
|
|
|
})();
|