diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2018-02-25 13:31:00 +0000 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2018-02-25 13:31:00 +0000 |
| commit | 1c9e90c1619d56f199c119874d09263acd827b07 (patch) | |
| tree | ea474cb0809d4ad27ba0460165d10eacb749fbe0 /query-executor.js | |
| parent | 11e98009906651acb110cd3b1625a771b1e2f472 (diff) | |
| download | sql-plus-plus-1c9e90c1619d56f199c119874d09263acd827b07.tar.xz sql-plus-plus-1c9e90c1619d56f199c119874d09263acd827b07.zip | |
Report connection errors. Add test connection functionality
Diffstat (limited to 'query-executor.js')
| -rw-r--r-- | query-executor.js | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/query-executor.js b/query-executor.js index 88df7e1..ee7552b 100644 --- a/query-executor.js +++ b/query-executor.js @@ -3,6 +3,8 @@ const { remote, ipcRenderer } = require("electron"); const { Pool } = require("pg"); +const connectionTestQuery = "SELECT now()"; + const executorId = require("uuid/v1")(); const connectionConfig = remote.getCurrentWindow().connectionConfig; @@ -15,8 +17,19 @@ const connectionPool = new Pool({ port: connectionConfig.port }); -// Initialisation completed -ipcRenderer.send("queryExecutor.initialiseConnectionCallback", executorId); +// Test the newly initialised connection +connectionPool.query(connectionTestQuery, (err, res) => { + setErrorCauseIfExists(err); + ipcRenderer.send("queryExecutor.initialiseConnectionCallback", {error: err, executorId: executorId}); +}); + +function setErrorCauseIfExists(error) { + if (error !== undefined) { + // The IPC payload is serialised to JSON before transmission, so the prototype chain is lost. + // So store the nicely formatted error message as a property. + error.cause = error.toString(); + } +} ipcRenderer.on("queryExecutor.runQuery", (event, payload) => { @@ -25,11 +38,7 @@ ipcRenderer.on("queryExecutor.runQuery", (event, payload) => { console.log(err, res); - if(err !== undefined) { - // The IPC payload is serialised to JSON beofre transmisison, so the protoype chain is lost. - // So store the nicely formatted error message as a property. - err.cause = err.toString(); - } + setErrorCauseIfExists(err); ipcRenderer.send("queryExecutor.runQueryComplete", { "error": err, |