import NoteContextAwareWidget from "./note_context_aware_widget.js"; const TPL = `
`; export default class SqlResultWidget extends NoteContextAwareWidget { isEnabled() { return this.note && this.note.mime === 'text/x-sqlite;schema=trilium' && super.isEnabled(); } doRender() { this.$widget = $(TPL); this.$resultContainer = this.$widget.find('.sql-console-result-container'); this.$noRowsAlert = this.$widget.find('.sql-query-no-rows'); } async sqlQueryResultsEvent({ntxId, results}) { if (!this.isNoteContext(ntxId)) { return; } this.$noRowsAlert.toggle(results.length === 1 && results[0].length === 0); this.$resultContainer.toggle(results.length > 1 || results[0].length > 0); this.$resultContainer.empty(); for (const rows of results) { if (!rows.length) { continue; } const $table = $(''); this.$resultContainer.append($table); const result = rows[0]; const $row = $(""); for (const key in result) { $row.append($(""); for (const key in result) { $row.append($("
").html(key)); } $table.append($row); for (const result of rows) { const $row = $("
").html(result[key])); } $table.append($row); } } } }