aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/tester1.c-pp.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2023-08-18 14:16:26 +0000
committerstephan <stephan@noemail.net>2023-08-18 14:16:26 +0000
commitccbfe97cd5ff9138cfe6134657aae13e9d27bcf5 (patch)
treeba057795f172a2bd15584b3ace107ef952943996 /ext/wasm/tester1.c-pp.js
parentabfe646c1223ff8b8c7e9de1ea69da75ff8136b7 (diff)
downloadsqlite-ccbfe97cd5ff9138cfe6134657aae13e9d27bcf5.tar.gz
sqlite-ccbfe97cd5ff9138cfe6134657aae13e9d27bcf5.zip
Extend the importDb() method of both OPFS VFSes to (A) support reading in an async streaming fashion via a callback and (B) automatically disable WAL mode in the imported db.
FossilOrigin-Name: 9b1398c96a4fd0b59e65faa8d5c98de4129f0f0357732f12cb2f5c53a08acdc2
Diffstat (limited to 'ext/wasm/tester1.c-pp.js')
-rw-r--r--ext/wasm/tester1.c-pp.js45
1 files changed, 42 insertions, 3 deletions
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js
index bd945dcab..f694598ea 100644
--- a/ext/wasm/tester1.c-pp.js
+++ b/ext/wasm/tester1.c-pp.js
@@ -2939,8 +2939,27 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
let db;
try {
const exp = this.opfsDbExport;
+ const filename = this.opfsDbFile;
delete this.opfsDbExport;
- this.opfsImportSize = await sqlite3.oo1.OpfsDb.importDb(this.opfsDbFile, exp);
+ this.opfsImportSize = await sqlite3.oo1.OpfsDb.importDb(filename, exp);
+ db = new sqlite3.oo1.OpfsDb(this.opfsDbFile);
+ T.assert(6 === db.selectValue('select count(*) from p')).
+ assert( this.opfsImportSize == exp.byteLength );
+ db.close();
+ this.opfsUnlink(filename);
+ T.assert(!(await sqlite3.opfs.entryExists(filename)));
+ // Try again with a function as an input source:
+ let cursor = 0;
+ const blockSize = 512, end = exp.byteLength;
+ const reader = async function(){
+ if(cursor >= exp.byteLength){
+ return undefined;
+ }
+ const rv = exp.subarray(cursor, cursor+blockSize>end ? end : cursor+blockSize);
+ cursor += blockSize;
+ return rv;
+ };
+ this.opfsImportSize = await sqlite3.oo1.OpfsDb.importDb(filename, reader);
db = new sqlite3.oo1.OpfsDb(this.opfsDbFile);
T.assert(6 === db.selectValue('select count(*) from p')).
assert( this.opfsImportSize == exp.byteLength );
@@ -3059,8 +3078,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
const dbytes = u1.exportFile(dbName);
T.assert(dbytes.length >= 4096);
const dbName2 = '/exported.db';
- u1.importDb(dbName2, dbytes);
- T.assert( 2 == u1.getFileCount() );
+ let nWrote = u1.importDb(dbName2, dbytes);
+ T.assert( 2 == u1.getFileCount() )
+ .assert( dbytes.byteLength == nWrote );
let db2 = new u1.OpfsSAHPoolDb(dbName2);
T.assert(db2 instanceof sqlite3.oo1.DB)
.assert(3 === db2.selectValue('select count(*) from t'));
@@ -3069,6 +3089,25 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
.assert(false === u1.unlink(dbName2))
.assert(1 === u1.getFileCount())
.assert(1 === u1.getFileNames().length);
+ // Try again with a function as an input source:
+ let cursor = 0;
+ const blockSize = 1024, end = dbytes.byteLength;
+ const reader = async function(){
+ if(cursor >= dbytes.byteLength){
+ return undefined;
+ }
+ const rv = dbytes.subarray(cursor, cursor+blockSize>end ? end : cursor+blockSize);
+ cursor += blockSize;
+ return rv;
+ };
+ nWrote = await u1.importDb(dbName2, reader);
+ T.assert( 2 == u1.getFileCount() );
+ db2 = new u1.OpfsSAHPoolDb(dbName2);
+ T.assert(db2 instanceof sqlite3.oo1.DB)
+ .assert(3 === db2.selectValue('select count(*) from t'));
+ db2.close();
+ T.assert(true === u1.unlink(dbName2))
+ .assert(dbytes.byteLength == nWrote);
}
T.assert(true === u1.unlink(dbName))