diff --git a/packages/api/src/controllers/queryHistory.js b/packages/api/src/controllers/queryHistory.js
index e6a3ea07..c2ed112b 100644
--- a/packages/api/src/controllers/queryHistory.js
+++ b/packages/api/src/controllers/queryHistory.js
@@ -4,22 +4,29 @@ const path = require('path');
const { datadir } = require('../utility/directories');
const _ = require('lodash');
const { filterName } = require('dbgate-tools');
+const socket = require('../utility/socket');
function readCore(reader, skip, limit, filter) {
- return new Promise(resolve => {
+ return new Promise((resolve, reject) => {
const res = [];
let readed = 0;
reader.on('data', line => {
- const json = JSON.parse(line);
- if (filterName(filter, json.sql)) {
- if (!skip || readed >= skip) {
- res.push(json);
- }
- readed++;
- if (limit && readed > (skip || 0) + limit) {
- reader.destroy();
- resolve(res);
+ if (!line && !line.trim()) return;
+ try {
+ const json = JSON.parse(line);
+ if (filterName(filter, json.sql)) {
+ if (!skip || readed >= skip) {
+ res.push(json);
+ }
+ readed++;
+ if (limit && readed > (skip || 0) + limit) {
+ reader.destroy();
+ resolve(res);
+ }
}
+ } catch (err) {
+ reader.destroy();
+ reject(err);
}
});
reader.on('end', () => resolve(res));
@@ -41,5 +48,7 @@ module.exports = {
async write({ data }) {
const fileName = path.join(datadir(), 'query-history.jsonl');
await fs.appendFile(fileName, JSON.stringify(data) + '\n');
+ socket.emitChanged('query-history-changed');
+ return 'OK';
},
};
diff --git a/packages/web/src/widgets/HistoryWidget.svelte b/packages/web/src/widgets/HistoryWidget.svelte
index 66a356d0..36a1c169 100644
--- a/packages/web/src/widgets/HistoryWidget.svelte
+++ b/packages/web/src/widgets/HistoryWidget.svelte
@@ -8,6 +8,7 @@
import hasPermission from '../utility/hasPermission';
import { useFavorites } from '../utility/metadataLoaders';
+ import QueryHistoryList from './QueryHistoryList.svelte';
import WidgetColumnBar from './WidgetColumnBar.svelte';
import WidgetColumnBarItem from './WidgetColumnBarItem.svelte';
@@ -29,4 +30,7 @@
/>
+
+
+
diff --git a/packages/web/src/widgets/QueryHistoryList.svelte b/packages/web/src/widgets/QueryHistoryList.svelte
new file mode 100644
index 00000000..9eba88ae
--- /dev/null
+++ b/packages/web/src/widgets/QueryHistoryList.svelte
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+ {#each historyItems as item}
+
+
+
+ {item.sql}
+
+
+
+ {item.database}
+
+
+ {/each}
+
+
+