aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor-instance.js38
-rw-r--r--main.js2
-rw-r--r--package.json3
-rw-r--r--query-executor.js8
4 files changed, 35 insertions, 16 deletions
diff --git a/editor-instance.js b/editor-instance.js
index 3ec123a..cb26db7 100644
--- a/editor-instance.js
+++ b/editor-instance.js
@@ -6,10 +6,13 @@ require("jquery-ui");
require("jquery.tabulator");
const cm = require("codemirror");
require("codemirror/mode/sql/sql");
-require("codemirror/addon/hint/show-hint.js")
-require("codemirror/addon/hint/sql-hint.js")
+require("codemirror/addon/hint/show-hint.js");
+require("codemirror/addon/hint/sql-hint.js");
const Split = require("split.js");
+const editorInstanceId = require('uuid/v1')();
+console.log("instanceId=" + editorInstanceId);
+
const editorContext = cm(document.getElementById("editor"), {
value: "select *\nfrom information_schema.tables\n/\nselect now()\n/\nselect *\nfrom foo",
mode: "text/x-sql",
@@ -24,7 +27,7 @@ editorContext.on("cursorActivity", (instance) => {
$("#cursor-coords").text("Ln " + (parseInt(coords.line) + 1) + ", Col " + (parseInt(coords.ch) + 1));
});
-ipcRenderer.send("queryExecutor.queryTableMetadata");
+ipcRenderer.send("queryExecutor.queryTableMetadata", _generateIpcPayload());
ipcRenderer.on("queryExecutor.queryTableMetadataComplete", (event, response) => {
console.log(response);
cm.commands.autocomplete = function (cmInstance) {
@@ -47,9 +50,10 @@ function runQuery() {
_setExecutionStatusIndicator("RUNNING");
_startExecTimer();
- let query = findQuery();
+ let payload = _generateIpcPayload();
+ payload.query = findQuery();
- ipcRenderer.send("queryExecutor.runQuery", query);
+ ipcRenderer.send("queryExecutor.runQuery", payload);
}
/**
@@ -126,15 +130,25 @@ function _clearQueryMarks() {
editorContext.clearGutter("statement-pointer");
}
-ipcRenderer.on("queryExecutor.runQueryComplete", (event, response) => {
- _stopExecTimer();
- if (response.error === undefined) {
- handleResult(response.result);
- }
- else {
- handleError(response.error);
+function _generateIpcPayload() {
+ return {
+ editorInstanceId: editorInstanceId
}
+}
+ipcRenderer.on("queryExecutor.runQueryComplete", (event, response) => {
+ // TODO - new instances should register with the instance manager, and the manager should proxy IPC messages only to
+ // the webview which sent the message. Rather than sending to all instances and the instance having to check
+ // if they were the intended recipient
+ if (response.editorInstanceId === editorInstanceId) {
+ _stopExecTimer();
+ if (response.error === undefined) {
+ handleResult(response.result);
+ }
+ else {
+ handleError(response.error);
+ }
+ }
});
function _startExecTimer() {
diff --git a/main.js b/main.js
index 6c19d99..6cb76c8 100644
--- a/main.js
+++ b/main.js
@@ -59,6 +59,8 @@ app.on("activate", () => {
const { webContents } = require('electron');
+// TODO - only send messages to instance manager which will route request to correct webView, rather than
+// sending to all webViews
ipcMain.on("queryExecutor.runQueryComplete", (event, payload) => {
webContents.getAllWebContents().forEach((w) => {
w.send("queryExecutor.runQueryComplete", payload);
diff --git a/package.json b/package.json
index f0ab1d3..5f05487 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
"split.js": "1.3.5",
"jquery-ui": "1.12.1",
"jquery.tabulator": "3.4.2",
- "electron-tabs": "0.9.0"
+ "electron-tabs": "0.9.0",
+ "uuid": "3.2.1"
}
}
diff --git a/query-executor.js b/query-executor.js
index 7bd836d..871da9e 100644
--- a/query-executor.js
+++ b/query-executor.js
@@ -13,13 +13,14 @@ const connectionPool = new Pool({
ipcRenderer.on("queryExecutor.runQuery", (event, payload) => {
- connectionPool.query(payload, (err, res) => {
+ connectionPool.query(payload.query, (err, res) => {
console.log(err, res)
ipcRenderer.send("queryExecutor.runQueryComplete", {
"error": err,
- "result": res
+ "result": res,
+ "editorInstanceId": payload.editorInstanceId
});
});
@@ -50,7 +51,8 @@ ipcRenderer.on("queryExecutor.queryTableMetadata", (event, payload) => {
ipcRenderer.send("queryExecutor.queryTableMetadataComplete", {
"error": err,
- "result": tableMetadata
+ "result": tableMetadata,
+ "editorInstanceId": payload.editorInstanceId
});
});