mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixes for SQL console schema view
This commit is contained in:
parent
502026359c
commit
dad47d115f
@ -13,38 +13,15 @@ let codeEditor;
|
|||||||
|
|
||||||
$dialog.on("shown.bs.modal", e => initEditor());
|
$dialog.on("shown.bs.modal", e => initEditor());
|
||||||
|
|
||||||
function showDialog() {
|
async function showDialog() {
|
||||||
glob.activeDialog = $dialog;
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
|
await showTables();
|
||||||
|
|
||||||
$dialog.modal();
|
$dialog.modal();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initEditor() {
|
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) {
|
if (!codeEditor) {
|
||||||
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
||||||
|
|
||||||
@ -121,6 +98,32 @@ async function execute(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function showTables() {
|
||||||
|
const tables = await server.get('sql/schema');
|
||||||
|
|
||||||
|
$tables.empty();
|
||||||
|
|
||||||
|
for (const table of tables) {
|
||||||
|
const $tableLink = $('<button class="btn">').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))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tables.append($tableLink).append(" ");
|
||||||
|
|
||||||
|
$tableLink
|
||||||
|
.tooltip({html: true, title: $columns.html()})
|
||||||
|
.click(() => codeEditor.setValue("SELECT * FROM " + table.name + " LIMIT 100"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$query.bind('keydown', 'ctrl+return', execute);
|
$query.bind('keydown', 'ctrl+return', execute);
|
||||||
|
|
||||||
$executeButton.click(execute);
|
$executeButton.click(execute);
|
||||||
|
@ -894,3 +894,10 @@ div[data-notify="container"] {
|
|||||||
border: 1px solid var(--main-border-color);
|
border: 1px solid var(--main-border-color);
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#sql-console-tables button {
|
||||||
|
padding: 0.25rem 0.4rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
line-height: 0.5;
|
||||||
|
border-radius: 0.2rem;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user