1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-05 01:26:18 +00:00

Introduce sql console

Very bare bones, but functional. Results are displayed in JSON for the moment. The console should also perhaps be hidden by default, with a keyboard shortcut, and a setting in local storage.
This commit is contained in:
Jeremy Ruston 2023-07-18 21:54:01 +01:00
parent 83e7d32c8e
commit 979a1f746d
3 changed files with 52 additions and 0 deletions

View File

@ -50,6 +50,8 @@ self.sqlite3InitModule().then((sqlite3)=>{
$tw.sqlite3 = sqlite3;
var capi = $tw.sqlite3.capi, // C-style API
oo = $tw.sqlite3.oo1; // High-level OO API
// Boot the console
$tw.sqlConsole = new $tw.SqlConsole();
// Get version numbers
console.log("sqlite3 version",capi.sqlite3_libversion());
// Boot TiddlyWiki

View File

@ -2,5 +2,6 @@ title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup/bottombody
tags: $:/tags/RawMarkupWikified/BottomBody
`<script>`
{{$:/plugins/tiddlywiki/sqlite3store/sql-console.js}}
{{$:/plugins/tiddlywiki/sqlite3store/init-sqlite3.js}}
`</script>`

View File

@ -0,0 +1,49 @@
/*\
title: $:/plugins/tiddlywiki/sqlite3store/sql-console.js
type: application/javascript
SQL console for debugging
\*/
(function() {
$tw.SqlConsole = function SqlConsole() {
// Container
this.consoleContainer = document.createElement("div");
this.consoleContainer.appendChild(document.createTextNode("console for sqlite3"));
// Input box
this.consoleInput = document.createElement("textarea");
this.consoleInput.style.width = "100%";
this.consoleContainer.appendChild(this.consoleInput);
// Run button
this.consoleRunButton = document.createElement("button");
this.consoleRunButton.appendChild(document.createTextNode("run sql"));
this.consoleRunButton.addEventListener("click",this.runQuery.bind(this));
this.consoleContainer.appendChild(this.consoleRunButton);
// Output
this.consoleOutput = document.createElement("div");
this.consoleContainer.appendChild(this.consoleOutput);
// Insert into DOM
document.body.insertBefore(this.consoleContainer,document.body.firstChild);
};
$tw.SqlConsole.prototype.runQuery = function() {
let resultRows = [],
exception;
try {
$tw.wiki.sqlFunctions.db.exec({
sql: this.consoleInput.value,
rowMode: "object",
resultRows: resultRows
});
} catch(e) {
exception = e.toString();
}
var output = document.createElement("div");
output.appendChild(document.createTextNode(exception || JSON.stringify(resultRows)));
this.consoleOutput.insertBefore(output,this.consoleOutput.firstChild);
};
})();
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/sql-console.js