Skip to content

Build your personal knowledge base with Trilium Notes

fix SQL console

zadam669eaa7509be
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 0000000000..797acea53e
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -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>
\ No newline at end of file
diff --git a/package.json b/package.json
index a0fb97420e..c2642e397d 100644
--- a/package.json
+++ b/package.json
@@ -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": {
diff --git a/src/public/app/services/entrypoints.js b/src/public/app/services/entrypoints.js
index 191866aaae..bd33aab2c1 100644
--- a/src/public/app/services/entrypoints.js
+++ b/src/public/app/services/entrypoints.js
@@ -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");
diff --git a/src/public/app/widgets/sql_result.js b/src/public/app/widgets/sql_result.js
index c3c42d192a..895b0d1f16 100644
--- a/src/public/app/widgets/sql_result.js
+++ b/src/public/app/widgets/sql_result.js
@@ -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>");
diff --git a/src/public/app/widgets/sql_table_schemas.js b/src/public/app/widgets/sql_table_schemas.js
index bf6b9b3a48..d1e4d9e63c 100644
--- a/src/public/app/widgets/sql_table_schemas.js
+++ b/src/public/app/widgets/sql_table_schemas.js
@@ -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');
}
diff --git a/src/services/content_hash.js b/src/services/content_hash.js
index 4b9f4f67fc..33f2e730ce 100644
--- a/src/services/content_hash.js
+++ b/src/services/content_hash.js
@@ -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();
diff --git a/src/services/sync.js b/src/services/sync.js
index 082091b700..793fb2ecf7 100644
--- a/src/services/sync.js
+++ b/src/services/sync.js
@@ -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();