Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/wasm/tests/opfs/sahpool/digest-worker.js # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / wasm / tests / opfs / sahpool / digest-worker.js` 94 lines ยท 2506 bytes Raw Blame History 1 /* 2 2025-01-31 3 4 The author disclaims copyright to this source code. In place of a 5 legal notice, here is a blessing: 6 7 * May you do good and not evil. 8 * May you find forgiveness for yourself and forgive others. 9 * May you share freely, never taking more than you give. 10 11 *********************************************************************** 12 13 This file is part of testing the OPFS SAHPool VFS's computeDigest() 14 fix. See ./digest.html for the details. 15 */ 16 const clog = console.log.bind(console); 17 const wPost = (type,...args)=>postMessage({type, payload:args}); 18 const log = (...args)=>{ 19 clog("Worker:",...args); 20 wPost('log',...args); 21 } 22 23 const hasOpfs = ()=>{ 24 return globalThis.FileSystemHandle 25 && globalThis.FileSystemDirectoryHandle 26 && globalThis.FileSystemFileHandle 27 && globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle 28 && navigator?.storage?.getDirectory; 29 }; 30 if( !hasOpfs() ){ 31 wPost('error',"OPFS not detected"); 32 throw new Error("OPFS not detected"); 33 } 34 35 clog("Importing sqlite3..."); 36 const searchParams = new URL(self.location.href).searchParams; 37 importScripts(searchParams.get('sqlite3.dir') + '/sqlite3.js'); 38 39 const runTests = function(sqlite3, poolUtil){ 40 const fname = '/my.db'; 41 let db = new poolUtil.OpfsSAHPoolDb(fname); 42 let n = (new Date()).valueOf(); 43 try { 44 db.exec([ 45 "create table if not exists t(a);" 46 ]); 47 db.exec({ 48 sql: "insert into t(a) values(?)", 49 bind: n++ 50 }); 51 log(fname,"record count: ",db.selectValue("select count(*) from t")); 52 }finally{ 53 db.close(); 54 } 55 56 db = new poolUtil.OpfsSAHPoolDb(fname); 57 try { 58 db.exec({ 59 sql: "insert into t(a) values(?)", 60 bind: n++ 61 }); 62 log(fname,"record count: ",db.selectValue("select count(*) from t")); 63 }finally{ 64 db.close(); 65 } 66 67 const fname2 = '/my2.db'; 68 db = new poolUtil.OpfsSAHPoolDb(fname2); 69 try { 70 db.exec([ 71 "create table if not exists t(a);" 72 ]); 73 db.exec({ 74 sql: "insert into t(a) values(?)", 75 bind: n++ 76 }); 77 log(fname2,"record count: ",db.selectValue("select count(*) from t")); 78 }finally{ 79 db.close(); 80 } 81 }; 82 83 globalThis.sqlite3InitModule().then(async function(sqlite3){ 84 log("sqlite3 version:",sqlite3.version); 85 const sahPoolConfig = { 86 name: 'opfs-sahpool-digest', 87 clearOnInit: false, 88 initialCapacity: 6 89 }; 90 return sqlite3.installOpfsSAHPoolVfs(sahPoolConfig).then(poolUtil=>{ 91 log('vfs acquired'); 92 runTests(sqlite3, poolUtil); 93 }); 94 });