1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

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
This commit is contained in:
stephan
2022-11-01 07:49:49 +00:00
parent c7dd9b60eb
commit 49048b148e
14 changed files with 341 additions and 106 deletions

View File

@@ -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);
}