diff options
author | stephan <stephan@noemail.net> | 2022-11-01 07:49:49 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-11-01 07:49:49 +0000 |
commit | 49048b148eac5f74eb6f1e9dfbd85ee8f95694a4 (patch) | |
tree | 6fcd456e95de58e06c0498c2b271da54051934ac /ext/wasm/api/sqlite3-api-worker1.js | |
parent | c7dd9b60eb95ebd65e53ed238e77ecfe6247b3b0 (diff) | |
download | sqlite-49048b148eac5f74eb6f1e9dfbd85ee8f95694a4.tar.gz sqlite-49048b148eac5f74eb6f1e9dfbd85ee8f95694a4.zip |
Significant cleanups and expansion of the sqlite3.opfs utilities. Add oo1.DB.dbVfsName(). Add VFS name to worker1:open's arguments and result.
FossilOrigin-Name: 86a341d7e061f946b39e8647ddd4743013b851b33ae9e6e755d8dbc53fba5286
Diffstat (limited to 'ext/wasm/api/sqlite3-api-worker1.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-worker1.js | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/ext/wasm/api/sqlite3-api-worker1.js b/ext/wasm/api/sqlite3-api-worker1.js index aa438a52d..532d61b67 100644 --- a/ext/wasm/api/sqlite3-api-worker1.js +++ b/ext/wasm/api/sqlite3-api-worker1.js @@ -188,6 +188,8 @@ See the sqlite3.oo1.DB constructor for peculiarities and transformations, + vfs: sqlite3_vfs name. Ignored if filename is ":memory:" or "". + This may change how the given filename is resolved. } } ``` @@ -212,6 +214,7 @@ persistent: true if the given filename resides in the known-persistent storage, else false. + vfs: name of the VFS the "main" db is using. } } ``` @@ -362,7 +365,7 @@ sqlite3.initWorker1API = function(){ /** Temp holder for "transferable" postMessage() state. */ xfer: [], open: function(opt){ - const db = new DB(opt.filename); + const db = new DB(opt); this.dbs[getDbId(db)] = db; if(this.dbList.indexOf(db)<0) this.dbList.push(db); return db; @@ -442,12 +445,14 @@ sqlite3.initWorker1API = function(){ oargs.filename = args.filename || ''; }else{ oargs.filename = args.filename; + oargs.vfs = args.vfs; } const db = wState.open(oargs); rc.filename = db.filename; rc.persistent = (!!pDir && db.filename.startsWith(pDir+'/')) || !!sqlite3.capi.sqlite3_js_db_uses_vfs(db.pointer, "opfs"); rc.dbId = getDbId(db); + rc.vfs = db.dbVfsName(); return rc; }, @@ -528,6 +533,7 @@ sqlite3.initWorker1API = function(){ rc.wasmfsOpfsEnabled = !!sqlite3.capi.sqlite3_wasmfs_opfs_dir(); rc.version = sqlite3.version; rc.vfsList = sqlite3.capi.sqlite3_js_vfs_list(); + rc.opfsEnabled = !!sqlite3.opfs; return rc; }, @@ -542,11 +548,6 @@ sqlite3.initWorker1API = function(){ } */ export: function(ev){ - /** - We need to reimplement this to use the Emscripten FS - interface. That part used to be in the OO#1 API but that - dependency was removed from that level of the API. - */ const db = getMsgDb(ev); const response = { bytearray: sqlite3.capi.sqlite3_js_db_export(db.pointer), @@ -559,17 +560,23 @@ sqlite3.initWorker1API = function(){ toss: function(ev){ toss("Testing worker exception"); + }, + + 'opfs-tree': async function(ev){ + if(!sqlite3.opfs) toss("OPFS support is unavailable."); + const response = await sqlite3.opfs.treeList(); + return response; } }/*wMsgHandler*/; - self.onmessage = function(ev){ + self.onmessage = async function(ev){ ev = ev.data; let result, dbId = ev.dbId, evType = ev.type; const arrivalTime = performance.now(); try { if(wMsgHandler.hasOwnProperty(evType) && wMsgHandler[evType] instanceof Function){ - result = wMsgHandler[evType](ev); + result = await wMsgHandler[evType](ev); }else{ toss("Unknown db worker message type:",ev.type); } |