4 The author disclaims copyright to this source code. In place of a
5 legal notice, here is a blessing:
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.
11 ***********************************************************************
13 A basic test script for sqlite3-api.js. This file must be run in
14 main JS thread and sqlite3.js must have been loaded before it.
16 import sqlite3InitModule from './jswasm/sqlite3-wasmfs.mjs';
17 //console.log('sqlite3InitModule =',sqlite3InitModule);
18 const toss = function(...args){throw new Error(args.join(' '))};
19 const log = console.log.bind(console),
20 warn = console.warn.bind(console),
21 error = console.error.bind(console);
26 const test1 = function(db){
27 db.exec("create table if not exists t(a);")
28 .transaction(function(db){
29 db.prepare("insert into t(a) values(?)")
30 .bind(new Date().getTime())
32 stdout("Number of values in table t:",
33 db.selectValue("select count(*) from t"));
37 const runTests = function(sqlite3){
38 const capi = sqlite3.capi,
41 stdout("Loaded module:",sqlite3);
42 stdout("Loaded sqlite3:",capi.sqlite3_libversion(), capi.sqlite3_sourceid());
43 const persistentDir = capi.sqlite3_wasmfs_opfs_dir();
45 stdout("Persistent storage dir:",persistentDir);
47 stderr("No persistent storage available.");
49 const startTime = performance.now();
52 db = new oo.DB(persistentDir+'/foo.db');
53 stdout("DB filename:",db.filename);
54 const banner1 = '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',
55 banner2 = '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
59 const n = performance.now();
60 stdout(banner1,"Running",f.name+"()...");
62 stdout(banner2,f.name+"() took ",(performance.now() - n),"ms");
67 stdout("Total test time:",(performance.now() - startTime),"ms");
70 sqlite3InitModule().then(runTests);