1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-01 09:43:16 +00:00

Test code to exercise the database

This commit is contained in:
jeremy@jermolene.com 2023-06-23 12:40:59 +01:00
parent 146a22b894
commit 449e2274e2
2 changed files with 27 additions and 0 deletions

View File

@ -52,6 +52,10 @@ self.sqlite3InitModuleState.urlParams.set("sqlite3.wasm",blobUrl);
self.sqlite3InitModule().then((sqlite3)=>{
// Save a reference to the sqlite3 object
$tw.sqlite3 = sqlite3;
var capi = $tw.sqlite3.capi, // C-style API
oo = $tw.sqlite3.oo1; // High-level OO API
// Get version numbers
console.log("sqlite3 version",capi.sqlite3_libversion());
// Boot TiddlyWiki
$tw.boot.boot();
});

View File

@ -18,6 +18,29 @@ $tw.boot.preloadDirty = $tw.boot.preloadDirty || [];
$tw.boot.suppressBoot = true;
$tw.Wiki = function(options) {
var capi = $tw.sqlite3.capi, // C-style API
oo = $tw.sqlite3.oo1; // High-level OO API
// Create a test database and store and retrieve some data
var db = new oo.DB("/tiddlywiki.sqlite3","ct");
db.exec({
sql:"CREATE TABLE IF NOT EXISTS t(a,b)"
});
db.exec({
sql: "insert into t(a,b) values (?,?)",
bind: [3, 1415926]
});
db.exec({
sql: "insert into t(a,b) values (?,?)",
bind: [1, 4142136]
});
let resultRows = [];
db.exec({
sql: "select a, b from t order by a limit 3",
rowMode: "object",
resultRows: resultRows
});
console.log("Result rows:",JSON.stringify(resultRows,undefined,2));
// Plain JS wiki store implementation follows
options = options || {};
var self = this,
tiddlers = Object.create(null), // Hashmap of tiddlers