From f4a63eae2aca2a84647a5027137614950aef1eac Mon Sep 17 00:00:00 2001
From: Topollo <30502407+raliqala@users.noreply.github.com>
Date: Sun, 6 Mar 2022 02:20:10 +0200
Subject: [PATCH 1/2] feat(PostgreSQL): :sparkles: Postgress connection string
feature for local and server connection string
This feature is based on this [issue](https://github.com/Fabio286/antares/issues/193) I tested with the following posgress connection strings postgresql://postgres:pgpassword@127.0.0.1:5432/my_local_databse?connection=local postgres://serveruser:serverpass@test.db.elephantsql.com/my_remote_databse?connection=server postgres://serveruser:serverpass@test.db.elephantsql.com:5432/my_remote_databse postgresql://postgres:pgpassword@127.0.0.1:5432/my_local_databse.
The connection string decoder is loaded before "test-connection", "check-connection", and "connect"
---
...che_logs2022-03-05T07_59_37_036Z-debug.log | 0
package.json | 3 +-
src/renderer/components/BaseMap.vue | 18 +--
.../WorkspaceAddConnectionPanel.vue | 16 ++-
.../WorkspaceEditConnectionPanel.vue | 13 ++
src/renderer/i18n/en-US.js | 3 +-
src/renderer/ipc-api/Connection.js | 13 +-
src/renderer/libs/connStringDecode.js | 112 ++++++++++++++++++
8 files changed, 162 insertions(+), 16 deletions(-)
create mode 100644 UsersraliqAppDataLocalnpm-cache_logs2022-03-05T07_59_37_036Z-debug.log
create mode 100644 src/renderer/libs/connStringDecode.js
diff --git a/UsersraliqAppDataLocalnpm-cache_logs2022-03-05T07_59_37_036Z-debug.log b/UsersraliqAppDataLocalnpm-cache_logs2022-03-05T07_59_37_036Z-debug.log
new file mode 100644
index 00000000..e69de29b
diff --git a/package.json b/package.json
index 4920ee1c..820d1bd8 100644
--- a/package.json
+++ b/package.json
@@ -109,7 +109,7 @@
"@turf/helpers": "^6.5.0",
"@vscode/vscode-languagedetection": "^1.0.21",
"ace-builds": "^1.4.13",
- "better-sqlite3": "^7.4.4",
+ "better-sqlite3": "^7.5.0",
"electron-log": "^4.4.1",
"electron-store": "^8.0.1",
"electron-updater": "^4.6.1",
@@ -142,6 +142,7 @@
"electron": "^17.0.1",
"electron-builder": "^22.14.11",
"electron-devtools-installer": "^3.2.0",
+ "electron-rebuild": "^3.2.7",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.24.2",
diff --git a/src/renderer/components/BaseMap.vue b/src/renderer/components/BaseMap.vue
index c1cbb836..e4424a83 100644
--- a/src/renderer/components/BaseMap.vue
+++ b/src/renderer/components/BaseMap.vue
@@ -93,16 +93,16 @@ export default {
diff --git a/src/renderer/components/WorkspaceAddConnectionPanel.vue b/src/renderer/components/WorkspaceAddConnectionPanel.vue
index 8d6b144c..d16b2ed9 100644
--- a/src/renderer/components/WorkspaceAddConnectionPanel.vue
+++ b/src/renderer/components/WorkspaceAddConnectionPanel.vue
@@ -45,6 +45,19 @@
>
+
+
diff --git a/src/renderer/i18n/en-US.js b/src/renderer/i18n/en-US.js
index b812c506..1ee3b26b 100644
--- a/src/renderer/i18n/en-US.js
+++ b/src/renderer/i18n/en-US.js
@@ -126,7 +126,8 @@ module.exports = {
enable: 'Enable',
disable: 'Disable',
commit: 'Commit',
- rollback: 'Rollback'
+ rollback: 'Rollback',
+ connectionString: 'Conn String'
},
message: {
appWelcome: 'Welcome to Antares SQL Client!',
diff --git a/src/renderer/ipc-api/Connection.js b/src/renderer/ipc-api/Connection.js
index 03d20938..c6dad0f9 100644
--- a/src/renderer/ipc-api/Connection.js
+++ b/src/renderer/ipc-api/Connection.js
@@ -1,20 +1,25 @@
'use strict';
import { ipcRenderer } from 'electron';
+import connStringConstruct from '../libs/connStringDecode';
+
export default class {
- static makeTest (params) {
+ static makeTest(params) {
+ params = connStringConstruct(params);
return ipcRenderer.invoke('test-connection', params);
}
- static checkConnection (params) {
+ static checkConnection(params) {
+ params = connStringConstruct(params);
return ipcRenderer.invoke('check-connection', params);
}
- static connect (params) {
+ static connect(params) {
+ params = connStringConstruct(params);
return ipcRenderer.invoke('connect', params);
}
- static disconnect (uid) {
+ static disconnect(uid) {
return ipcRenderer.invoke('disconnect', uid);
}
}
diff --git a/src/renderer/libs/connStringDecode.js b/src/renderer/libs/connStringDecode.js
new file mode 100644
index 00000000..a270f1cf
--- /dev/null
+++ b/src/renderer/libs/connStringDecode.js
@@ -0,0 +1,112 @@
+
+const getUrlScheme = pgString => {
+ const scheme = pgString ? pgString.split('://')[0] : '';
+
+ return scheme === 'postgresql' ? 'postgres' : scheme;
+};
+
+const passAndHost = part => {
+ const host = part.split('@')[1] === 'localhost' ? '127.0.0.1' : part.split('@')[1];
+ return [part.split('@')[0], host];
+};
+
+const portAndDb = part => {
+ return part.split('/');
+};
+
+const pass = (part) => {
+ return part.split('@');
+};
+
+const hostAndDb = (part) => {
+ return part.split('/');
+};
+
+const localConnectionString = (stringArgs, args) => {
+ let scheme = '';
+ if (getUrlScheme(stringArgs) === 'postgres' || getUrlScheme(stringArgs) === 'postgresql')
+ scheme = 'pg';
+
+ const values = stringArgs.split('://')[1];
+ const parts = values.split(':');
+
+ const userName = parts[0];
+
+ const password = passAndHost(parts[1])[0];
+ const host = passAndHost(parts[1])[1];
+
+ const port = portAndDb(parts[2])[0];
+ const dbName = portAndDb(parts[2])[1];
+
+ const client = args.client ? args.client : scheme;
+
+ args.client = client;
+ args.host = host;
+ args.database = dbName;
+ args.port = port;
+ args.user = userName;
+ args.password = password;
+
+ return args;
+};
+
+const onlineConnectionString = (stringArgs, args) => {
+ let scheme = '';
+ const defaultPort = '5432';
+ if (getUrlScheme(stringArgs) === 'postgres' || getUrlScheme(stringArgs) === 'postgresql')
+ scheme = 'pg';
+
+ const values = stringArgs.split('://')[1];
+ const parts = values.split(':');
+
+ const userName = parts[0];
+
+ const password = pass(parts[1])[0];
+
+ const host = hostAndDb(pass(parts[1])[1])[0];
+ const dbName = hostAndDb(pass(parts[1])[1])[1];
+
+ const port = defaultPort;
+
+ console.log(userName, password, host, dbName, port);
+
+ const client = args.client ? args.client : scheme;
+
+ args.client = client;
+ args.host = host;
+ args.database = dbName;
+ args.port = port;
+ args.user = userName;
+ args.password = password;
+
+ return args;
+};
+
+const connectionType = part => {
+ return part.split('=')[1];
+};
+
+const connStringConstruct = args => {
+ if (!args.pgConnString)
+ return args;
+
+ const pgConnString = args.pgConnString;
+
+ if (!pgConnString.includes('?'))
+ return localConnectionString(pgConnString, args);
+
+ const pgConnStringPrepared = pgConnString.split('?')[0];
+
+ switch (connectionType(pgConnString.split('?')[1])) {
+ case 'local':
+ return localConnectionString(pgConnStringPrepared, args);
+
+ case 'server':
+ return onlineConnectionString(pgConnStringPrepared, args);
+
+ default:
+ return args;
+ };
+};
+
+export default connStringConstruct;
From cc02e2c5a8be78742bf697f3476ae5aed5e40bf0 Mon Sep 17 00:00:00 2001
From: Fabio Di Stasio
Date: Sun, 6 Mar 2022 09:40:11 +0100
Subject: [PATCH 2/2] refactor(PostgreSQL): minor refactor on UI and code for
pg connection string
---
package.json | 1 -
.../WorkspaceAddConnectionPanel.vue | 26 +++++++++----------
.../WorkspaceEditConnectionPanel.vue | 26 +++++++++----------
src/renderer/i18n/en-US.js | 2 +-
src/renderer/ipc-api/Connection.js | 15 +++++------
src/renderer/libs/connStringDecode.js | 2 --
6 files changed, 34 insertions(+), 38 deletions(-)
diff --git a/package.json b/package.json
index 820d1bd8..fd1b89b7 100644
--- a/package.json
+++ b/package.json
@@ -142,7 +142,6 @@
"electron": "^17.0.1",
"electron-builder": "^22.14.11",
"electron-devtools-installer": "^3.2.0",
- "electron-rebuild": "^3.2.7",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.24.2",
diff --git a/src/renderer/components/WorkspaceAddConnectionPanel.vue b/src/renderer/components/WorkspaceAddConnectionPanel.vue
index d16b2ed9..276f2d48 100644
--- a/src/renderer/components/WorkspaceAddConnectionPanel.vue
+++ b/src/renderer/components/WorkspaceAddConnectionPanel.vue
@@ -45,19 +45,6 @@
>
-
+
-
+