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 @@ > +
+
+ +
+
+ +
+
@@ -412,7 +425,8 @@ export default { sshUser: '', sshPass: '', sshKey: '', - sshPort: 22 + sshPort: 22, + pgConnString: '' }, isConnecting: false, isTesting: false, diff --git a/src/renderer/components/WorkspaceEditConnectionPanel.vue b/src/renderer/components/WorkspaceEditConnectionPanel.vue index c62a02bf..4cd04512 100644 --- a/src/renderer/components/WorkspaceEditConnectionPanel.vue +++ b/src/renderer/components/WorkspaceEditConnectionPanel.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;