fix SQL console

This commit is contained in:
zadam 2021-07-27 22:08:41 +02:00
parent f50084dc1b
commit 669eaa7509
7 changed files with 32 additions and 30 deletions

10
.idea/runConfigurations.xml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -57,7 +57,7 @@
"jimp": "0.16.1",
"joplin-turndown-plugin-gfm": "1.0.12",
"jsdom": "16.6.0",
"mime-types": "2.1.31",
"mime-types": "2.1.32",
"multer": "1.4.2",
"node-abi": "2.30.0",
"open": "8.2.1",
@ -90,7 +90,7 @@
"jsdoc": "3.6.7",
"lorem-ipsum": "2.0.3",
"rcedit": "3.0.1",
"webpack": "5.46.0",
"webpack": "5.47.0",
"webpack-cli": "4.7.2"
},
"optionalDependencies": {

View File

@ -194,8 +194,7 @@ export default class Entrypoints extends Component {
}
async runActiveNoteCommand() {
const noteContext = appContext.tabManager.getActiveContext();
const note = noteContext.note;
const {ntxId, note} = appContext.tabManager.getActiveContext();
// ctrl+enter is also used elsewhere so make sure we're running only when appropriate
if (!note || note.type !== 'code') {
@ -208,9 +207,9 @@ export default class Entrypoints extends Component {
} else if (note.mime.endsWith("env=backend")) {
await server.post('script/run/' + note.noteId);
} else if (note.mime === 'text/x-sqlite;schema=trilium') {
const result = await server.post("sql/execute/" + note.noteId);
const {results} = await server.post("sql/execute/" + note.noteId);
this.triggerEvent('sqlQueryResults', {ntxId: noteContext.ntxId, results: result.results});
await appContext.triggerEvent('sqlQueryResults', {ntxId: ntxId, results: results});
}
toastService.showMessage("Note executed");

View File

@ -8,6 +8,10 @@ const TPL = `
}
</style>
<div class="sql-query-no-rows alert alert-info" style="display: none;">
No rows have been returned for this query.
</div>
<div class="sql-console-result-container"></div>
</div>`;
@ -21,7 +25,8 @@ export default class SqlResultWidget extends NoteContextAwareWidget {
doRender() {
this.$widget = $(TPL);
this.$sqlConsoleResultContainer = this.$widget.find('.sql-console-result-container');
this.$resultContainer = this.$widget.find('.sql-console-result-container');
this.$noRowsAlert = this.$widget.find('.sql-query-no-rows');
}
async sqlQueryResultsEvent({ntxId, results}) {
@ -29,7 +34,10 @@ export default class SqlResultWidget extends NoteContextAwareWidget {
return;
}
this.$sqlConsoleResultContainer.empty();
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) {
@ -37,7 +45,7 @@ export default class SqlResultWidget extends NoteContextAwareWidget {
}
const $table = $('<table class="table table-striped">');
this.$sqlConsoleResultContainer.append($table);
this.$resultContainer.append($table);
const result = rows[0];
const $row = $("<tr>");

View File

@ -8,6 +8,10 @@ import toastService from "../services/toast.js";
const TPL = `
<div class="sql-table-schemas-widget">
<style>
.sql-table-schemas-widget {
padding: 12px;
}
.sql-table-schemas button {
padding: 0.25rem 0.4rem;
font-size: 0.875rem;
@ -42,6 +46,7 @@ export default class SqlTableSchemasWidget extends NoteContextAwareWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$sqlConsoleTableSchemas = this.$widget.find('.sql-table-schemas');
}

View File

@ -4,26 +4,6 @@ const sql = require('./sql');
const utils = require('./utils');
const log = require('./log');
function getSectorHashes(tableName, primaryKeyName, whereBranch) {
const hashes = sql.getRows(`SELECT ${primaryKeyName} AS id, hash FROM ${tableName}`
+ (whereBranch ? ` WHERE ${whereBranch} ` : ''));
// sorting is faster in memory
hashes.sort((a, b) => a.id < b.id ? -1 : 1);
const map = {};
for (const {id, hash} of hashes) {
map[id[0]] = (map[id[0]] || "") + hash;
}
for (const key in map) {
map[key] = utils.hash(map[key]);
}
return map;
}
function getEntityHashes() {
const startTime = new Date();

View File

@ -396,7 +396,7 @@ require("../becca/becca_loader").beccaLoaded.then(() => {
setInterval(cls.wrap(sync), 60000);
// kickoff initial sync immediately
setTimeout(cls.wrap(sync), 5000);
setTimeout(cls.wrap(sync), 2000);
// called just so ws.setLastSyncedPush() is called
getLastSyncedPush();