aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/test-opfs-vfs.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-09-18 17:32:35 +0000
committerstephan <stephan@noemail.net>2022-09-18 17:32:35 +0000
commitf38601206997aa909b2cd6dba02cb0b4e13e8e2a (patch)
tree7968c95b16ea078621e051c56bfd46b7e1197ce7 /ext/wasm/test-opfs-vfs.js
parent0db3089576b6df43fa477100446ab330b5bda905 (diff)
downloadsqlite-f38601206997aa909b2cd6dba02cb0b4e13e8e2a.tar.gz
sqlite-f38601206997aa909b2cd6dba02cb0b4e13e8e2a.zip
Numerous cleanups in the JS bits. Removed some now-defunct wasm test files. Expose sqlite3.opfs object containing various OPFS-specific utilities.
FossilOrigin-Name: 26e625d05d9820033b23536f18ad3ddc59ed712ad507d4b0c7fe88abd15d2be8
Diffstat (limited to 'ext/wasm/test-opfs-vfs.js')
-rw-r--r--ext/wasm/test-opfs-vfs.js34
1 files changed, 24 insertions, 10 deletions
diff --git a/ext/wasm/test-opfs-vfs.js b/ext/wasm/test-opfs-vfs.js
index fd71c9cdc..04497c1c1 100644
--- a/ext/wasm/test-opfs-vfs.js
+++ b/ext/wasm/test-opfs-vfs.js
@@ -34,12 +34,16 @@ const tryOpfsVfs = function(sqlite3){
const oVfs = capi.sqlite3_vfs.instanceForPointer(pVfs) || toss("Unexpected instanceForPointer() result.");;
log("OPFS VFS:",pVfs, oVfs);
+ const urlArgs = new URL(self.location.href).searchParams;
const dbFile = "my-persistent.db";
- const db = new sqlite3.oo1.DB(dbFile, "c", "opfs");
+ if(urlArgs.has('delete')) sqlite3.opfs.deleteEntry(dbFile);
+
+ const opfs = sqlite3.opfs;
+ const db = new opfs.OpfsDb(dbFile);
log("db file:",db.filename);
try{
- let n = db.selectValue("select count(*) from sqlite_schema");
- if(n){
+ if(opfs.entryExists(dbFile)){
+ let n = db.selectValue("select count(*) from sqlite_schema");
log("Persistent data found. sqlite_schema entry count =",n);
}
db.transaction((db)=>{
@@ -54,6 +58,17 @@ const tryOpfsVfs = function(sqlite3){
});
});
log("count(*) from t =",db.selectValue("select count(*) from t"));
+
+ // Some sanity checks of the opfs utility functions...
+ const testDir = '/sqlite3-opfs-'+opfs.randomFilename(12);
+ const aDir = testDir+'/test/dir';
+ opfs.mkdir(aDir) || toss("mkdir failed");
+ opfs.mkdir(aDir) || toss("mkdir must pass if the dir exists");
+ opfs.deleteEntry(testDir+'/test') && toss("delete 1 should have failed (dir not empty)");
+ opfs.deleteEntry(testDir+'/test/dir') || toss("delete 2 failed");
+ opfs.deleteEntry(testDir+'/test/dir') && toss("delete 2b should have failed (dir already deleted)");
+ opfs.deleteEntry(testDir,true) || toss("delete 3 failed");
+ opfs.entryExists(testDir) && toss("entryExists(",testDir,") should have failed");
}finally{
db.close();
}
@@ -62,10 +77,9 @@ const tryOpfsVfs = function(sqlite3){
}/*tryOpfsVfs()*/;
importScripts('sqlite3.js');
-self.sqlite3InitModule().then((EmscriptenModule)=>{
- EmscriptenModule.sqlite3.installOpfsVfs()
- .then((sqlite3)=>tryOpfsVfs(sqlite3))
- .catch((e)=>{
- console.error("Error initializing OPFS VFS:",e);
- });
-});
+self.sqlite3InitModule()
+ .then((EmscriptenModule)=>EmscriptenModule.sqlite3.installOpfsVfs())
+ .then((sqlite3)=>tryOpfsVfs(sqlite3))
+ .catch((e)=>{
+ console.error("Error initializing module:",e);
+ });