diff --git a/plugins/tiddlywiki/sqlite3store/init-sqlite3.js b/plugins/tiddlywiki/sqlite3store/init-sqlite3.js index 839fa9e34..45fef90d0 100644 --- a/plugins/tiddlywiki/sqlite3store/init-sqlite3.js +++ b/plugins/tiddlywiki/sqlite3store/init-sqlite3.js @@ -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 diff --git a/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.tid b/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.tid index ee187883a..ee3a350fb 100644 --- a/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.tid +++ b/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.tid @@ -2,5 +2,6 @@ title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup/bottombody tags: $:/tags/RawMarkupWikified/BottomBody `` diff --git a/plugins/tiddlywiki/sqlite3store/sql-console.js b/plugins/tiddlywiki/sqlite3store/sql-console.js new file mode 100644 index 000000000..23578e8a0 --- /dev/null +++ b/plugins/tiddlywiki/sqlite3store/sql-console.js @@ -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 \ No newline at end of file