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.
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 sqlite3:",capi
.sqlite3_libversion(), capi
.sqlite3_sourceid());
42 const persistentDir
= capi
.sqlite3_wasmfs_opfs_dir();
44 stdout("Persistent storage dir:",persistentDir
);
46 stderr("No persistent storage available.");
48 const startTime
= performance
.now();
51 db
= new oo
.DB(persistentDir
+'/foo.db');
52 stdout("DB filename:",db
.filename
);
53 const banner1
= '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>',
54 banner2
= '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
58 const n
= performance
.now();
59 stdout(banner1
,"Running",f
.name
+"()...");
61 stdout(banner2
,f
.name
+"() took ",(performance
.now() - n
),"ms");
66 stdout("Total test time:",(performance
.now() - startTime
),"ms");
69 sqlite3InitModule(self
.sqlite3TestModule
).then(runTests
);