mirror of
https://github.com/zadam/trilium.git
synced 2025-10-28 08:46:43 +01:00
sql console added to global menu and now has schema info
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import utils from '../services/utils.js';
|
||||
import libraryLoader from '../services/library_loader.js';
|
||||
import server from '../services/server.js';
|
||||
import infoService from "../services/info.js";
|
||||
@@ -8,6 +7,7 @@ const $query = $('#sql-console-query');
|
||||
const $executeButton = $('#sql-console-execute');
|
||||
const $resultHead = $('#sql-console-results thead');
|
||||
const $resultBody = $('#sql-console-results tbody');
|
||||
const $tables = $("#sql-console-tables");
|
||||
|
||||
let codeEditor;
|
||||
|
||||
@@ -20,6 +20,31 @@ function showDialog() {
|
||||
}
|
||||
|
||||
async function initEditor() {
|
||||
server.get('sql/schema').then(tables => {
|
||||
$tables.empty();
|
||||
|
||||
for (const table of tables) {
|
||||
const $tableLink = $('<a href="javascript:">').text(table.name);
|
||||
|
||||
const $columns = $("<table>");
|
||||
|
||||
for (const column of table.columns) {
|
||||
$columns.append(
|
||||
$("<tr>")
|
||||
.append($("<td>").text(column.name))
|
||||
.append($("<td>").text(column.type))
|
||||
);
|
||||
}
|
||||
|
||||
$tableLink
|
||||
.attr("title", $columns.html())
|
||||
.tooltip({ html: true })
|
||||
.click(() => codeEditor.setValue("SELECT * FROM " + table.name + " LIMIT 100"));
|
||||
|
||||
$tables.append($tableLink).append(" ");
|
||||
}
|
||||
});
|
||||
|
||||
if (!codeEditor) {
|
||||
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user