2022-09-17 23:50:12 +03:00
|
|
|
/*
|
|
|
|
2022-09-17
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
***********************************************************************
|
|
|
|
|
2022-09-18 05:35:30 +03:00
|
|
|
A testing ground for the OPFS VFS.
|
2022-09-18 00:13:26 +03:00
|
|
|
|
|
|
|
Summary of how this works:
|
|
|
|
|
|
|
|
This file uses the sqlite3.StructBinder-created struct wrappers for
|
|
|
|
sqlite3_vfs, sqlite3_io_methods, ans sqlite3_file to set up a
|
|
|
|
conventional sqlite3_vfs (except that it's implemented in JS). The
|
|
|
|
methods which require OPFS APIs use a separate worker (hereafter called the
|
|
|
|
OPFS worker) to access that functionality. This worker and that one
|
2022-09-18 05:35:30 +03:00
|
|
|
use SharedArrayBuffer.
|
2022-09-17 23:50:12 +03:00
|
|
|
*/
|
2022-09-17 18:08:22 +03:00
|
|
|
'use strict';
|
2022-09-18 05:35:30 +03:00
|
|
|
const tryOpfsVfs = function(sqlite3){
|
2022-09-17 23:50:12 +03:00
|
|
|
const toss = function(...args){throw new Error(args.join(' '))};
|
2022-09-18 05:35:30 +03:00
|
|
|
const logPrefix = "OPFS tester:";
|
2022-09-17 18:08:22 +03:00
|
|
|
const log = (...args)=>{
|
|
|
|
console.log(logPrefix,...args);
|
|
|
|
};
|
|
|
|
const warn = (...args)=>{
|
|
|
|
console.warn(logPrefix,...args);
|
|
|
|
};
|
|
|
|
const error = (...args)=>{
|
|
|
|
console.error(logPrefix,...args);
|
|
|
|
};
|
2022-09-18 05:35:30 +03:00
|
|
|
log("tryOpfsVfs()");
|
2022-09-17 23:50:12 +03:00
|
|
|
const capi = sqlite3.capi;
|
2022-09-18 05:35:30 +03:00
|
|
|
const pVfs = capi.sqlite3_vfs_find("opfs") || toss("Unexpectedly missing 'opfs' VFS.");
|
|
|
|
const oVfs = capi.sqlite3_vfs.instanceForPointer(pVfs);
|
|
|
|
log("OPFS VFS:",pVfs, oVfs);
|
|
|
|
log("Done!");
|
|
|
|
}/*tryOpfsVfs()*/;
|
2022-09-17 18:08:22 +03:00
|
|
|
|
|
|
|
importScripts('sqlite3.js');
|
2022-09-18 05:35:30 +03:00
|
|
|
self.sqlite3InitModule().then((EmscriptenModule)=>{
|
|
|
|
EmscriptenModule.sqlite3.installOpfsVfs()
|
|
|
|
.then((sqlite3)=>tryOpfsVfs(sqlite3))
|
|
|
|
.catch((e)=>{
|
|
|
|
console.error("Error initializing OPFS VFS:",e);
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
});
|