mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
perf(PostgreSQL): improved support of connection strings, closes #893
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@ -42,7 +42,6 @@
|
|||||||
"node-firebird": "~1.1.8",
|
"node-firebird": "~1.1.8",
|
||||||
"node-loader": "~2.0.0",
|
"node-loader": "~2.0.0",
|
||||||
"pg": "~8.11.5",
|
"pg": "~8.11.5",
|
||||||
"pg-connection-string": "~2.5.0",
|
|
||||||
"pg-query-stream": "~4.2.3",
|
"pg-query-stream": "~4.2.3",
|
||||||
"pgsql-ast-parser": "~7.2.1",
|
"pgsql-ast-parser": "~7.2.1",
|
||||||
"pinia": "~2.1.7",
|
"pinia": "~2.1.7",
|
||||||
@ -12142,10 +12141,6 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"node_modules/pg-connection-string": {
|
|
||||||
"version": "2.5.0",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/pg-cursor": {
|
"node_modules/pg-cursor": {
|
||||||
"version": "2.10.3",
|
"version": "2.10.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -24507,9 +24502,6 @@
|
|||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"pg-connection-string": {
|
|
||||||
"version": "2.5.0"
|
|
||||||
},
|
|
||||||
"pg-cursor": {
|
"pg-cursor": {
|
||||||
"version": "2.10.3",
|
"version": "2.10.3",
|
||||||
"requires": {}
|
"requires": {}
|
||||||
|
@ -151,7 +151,6 @@
|
|||||||
"node-firebird": "~1.1.8",
|
"node-firebird": "~1.1.8",
|
||||||
"node-loader": "~2.0.0",
|
"node-loader": "~2.0.0",
|
||||||
"pg": "~8.11.5",
|
"pg": "~8.11.5",
|
||||||
"pg-connection-string": "~2.5.0",
|
|
||||||
"pg-query-stream": "~4.2.3",
|
"pg-query-stream": "~4.2.3",
|
||||||
"pgsql-ast-parser": "~7.2.1",
|
"pgsql-ast-parser": "~7.2.1",
|
||||||
"pinia": "~2.1.7",
|
"pinia": "~2.1.7",
|
||||||
|
@ -57,6 +57,7 @@ export interface ConnectionParams {
|
|||||||
cert?: string;
|
cert?: string;
|
||||||
key?: string;
|
key?: string;
|
||||||
ca?: string;
|
ca?: string;
|
||||||
|
connString?: string;
|
||||||
untrustedConnection: boolean;
|
untrustedConnection: boolean;
|
||||||
ciphers?: string;
|
ciphers?: string;
|
||||||
ssh: boolean;
|
ssh: boolean;
|
||||||
|
@ -26,6 +26,7 @@ export default (connections: Record<string, antares.Client>) => {
|
|||||||
user: conn.user,
|
user: conn.user,
|
||||||
password: conn.password,
|
password: conn.password,
|
||||||
readonly: conn.readonly,
|
readonly: conn.readonly,
|
||||||
|
connectionString: conn.connString,
|
||||||
database: '',
|
database: '',
|
||||||
schema: '',
|
schema: '',
|
||||||
databasePath: '',
|
databasePath: '',
|
||||||
@ -122,6 +123,7 @@ export default (connections: Record<string, antares.Client>) => {
|
|||||||
password: conn.password,
|
password: conn.password,
|
||||||
application_name: 'Antares SQL',
|
application_name: 'Antares SQL',
|
||||||
readonly: conn.readonly,
|
readonly: conn.readonly,
|
||||||
|
connectionString: conn.connString,
|
||||||
database: '',
|
database: '',
|
||||||
schema: '',
|
schema: '',
|
||||||
databasePath: '',
|
databasePath: '',
|
||||||
|
@ -155,6 +155,7 @@ export class PostgreSQLClient extends BaseClient {
|
|||||||
host: this._params.host,
|
host: this._params.host,
|
||||||
port: this._params.port,
|
port: this._params.port,
|
||||||
user: this._params.user,
|
user: this._params.user,
|
||||||
|
connectionString: this._params.connectionString,
|
||||||
database: 'postgres' as string,
|
database: 'postgres' as string,
|
||||||
password: this._params.password,
|
password: this._params.password,
|
||||||
ssl: null as ConnectionOptions
|
ssl: null as ConnectionOptions
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
<div class="column col-7 col-sm-12">
|
<div class="column col-7 col-sm-12">
|
||||||
<input
|
<input
|
||||||
ref="pgString"
|
ref="pgString"
|
||||||
v-model="connection.pgConnString"
|
v-model="connection.connString"
|
||||||
class="form-input"
|
class="form-input"
|
||||||
type="text"
|
type="text"
|
||||||
>
|
>
|
||||||
@ -502,8 +502,8 @@ const connection = ref({
|
|||||||
sshKey: '',
|
sshKey: '',
|
||||||
sshPort: 22,
|
sshPort: 22,
|
||||||
sshKeepAliveInterval: 1800,
|
sshKeepAliveInterval: 1800,
|
||||||
pgConnString: ''
|
connString: ''
|
||||||
}) as Ref<ConnectionParams & { pgConnString: string }>;
|
}) as Ref<ConnectionParams & { connString: string }>;
|
||||||
|
|
||||||
const firstInput: Ref<HTMLInputElement> = ref(null);
|
const firstInput: Ref<HTMLInputElement> = ref(null);
|
||||||
const isConnecting = ref(false);
|
const isConnecting = ref(false);
|
||||||
|
@ -68,7 +68,7 @@
|
|||||||
<div class="column col-7 col-sm-12">
|
<div class="column col-7 col-sm-12">
|
||||||
<input
|
<input
|
||||||
ref="pgString"
|
ref="pgString"
|
||||||
v-model="localConnection.pgConnString"
|
v-model="localConnection.connString"
|
||||||
class="form-input"
|
class="form-input"
|
||||||
type="text"
|
type="text"
|
||||||
>
|
>
|
||||||
@ -502,7 +502,7 @@ const clients = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const firstInput: Ref<HTMLInputElement> = ref(null);
|
const firstInput: Ref<HTMLInputElement> = ref(null);
|
||||||
const localConnection: Ref<ConnectionParams & { pgConnString: string }> = ref(null);
|
const localConnection: Ref<ConnectionParams & { connString: string }> = ref(null);
|
||||||
const isConnecting = ref(false);
|
const isConnecting = ref(false);
|
||||||
const isTesting = ref(false);
|
const isTesting = ref(false);
|
||||||
const isAsking = ref(false);
|
const isAsking = ref(false);
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
import { ConnectionParams, IpcResponse } from 'common/interfaces/antares';
|
import { ConnectionParams, IpcResponse } from 'common/interfaces/antares';
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
|
|
||||||
import connStringConstruct from '../libs/connStringDecode';
|
|
||||||
import { unproxify } from '../libs/unproxify';
|
import { unproxify } from '../libs/unproxify';
|
||||||
|
|
||||||
export default class {
|
export default class {
|
||||||
static makeTest (params: ConnectionParams & { pgConnString?: string }): Promise<IpcResponse> {
|
static makeTest (params: ConnectionParams & { connString?: string }): Promise<IpcResponse> {
|
||||||
const newParams = connStringConstruct(params) as ConnectionParams;
|
return ipcRenderer.invoke('test-connection', unproxify(params));
|
||||||
return ipcRenderer.invoke('test-connection', unproxify(newParams));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static connect (params: ConnectionParams & { pgConnString?: string }): Promise<IpcResponse> {
|
static connect (params: ConnectionParams & { connString?: string }): Promise<IpcResponse> {
|
||||||
const newParams = connStringConstruct(params) as ConnectionParams;
|
return ipcRenderer.invoke('connect', unproxify(params));
|
||||||
return ipcRenderer.invoke('connect', unproxify(newParams));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static abortConnection (uid: string): void {
|
static abortConnection (uid: string): void {
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
import { ConnectionParams } from 'common/interfaces/antares';
|
|
||||||
import * as formatter from 'pg-connection-string'; // parses a connection string
|
|
||||||
|
|
||||||
const formatHost = (host: string) => {
|
|
||||||
const results = host === 'localhost' ? '127.0.0.1' : host;
|
|
||||||
return results;
|
|
||||||
};
|
|
||||||
|
|
||||||
const checkForSSl = (conn: string) => {
|
|
||||||
return conn.includes('ssl=true');
|
|
||||||
};
|
|
||||||
|
|
||||||
const connStringConstruct = (args: ConnectionParams & { pgConnString?: string }): ConnectionParams => {
|
|
||||||
if (!args.pgConnString)
|
|
||||||
return args;
|
|
||||||
|
|
||||||
if (typeof args.pgConnString !== 'string')
|
|
||||||
return args;
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const stringArgs: any = formatter.parse(args.pgConnString);
|
|
||||||
|
|
||||||
const client = args.client || 'pg';
|
|
||||||
|
|
||||||
args.client = client;
|
|
||||||
args.host = formatHost(stringArgs.host);
|
|
||||||
args.database = stringArgs.database;
|
|
||||||
args.port = stringArgs.port || '5432';
|
|
||||||
args.user = stringArgs.user;
|
|
||||||
args.password = stringArgs.password;
|
|
||||||
|
|
||||||
// ssh
|
|
||||||
args.ssh = stringArgs.ssh || args.ssh;
|
|
||||||
args.sshHost = stringArgs.sshHost;
|
|
||||||
args.sshUser = stringArgs.sshUser;
|
|
||||||
args.sshPass = stringArgs.sshPass;
|
|
||||||
args.sshKey = stringArgs.sshKey;
|
|
||||||
args.sshPort = stringArgs.sshPort;
|
|
||||||
|
|
||||||
// ssl mode
|
|
||||||
args.ssl = checkForSSl(args.pgConnString) || args.ssl;
|
|
||||||
args.cert = stringArgs.sslcert;
|
|
||||||
args.key = stringArgs.sslkey;
|
|
||||||
args.ca = stringArgs.sslrootcert;
|
|
||||||
args.ciphers = stringArgs.ciphers;
|
|
||||||
|
|
||||||
return args;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default connStringConstruct;
|
|
@ -147,7 +147,7 @@ export const useWorkspacesStore = defineStore('workspaces', {
|
|||||||
else
|
else
|
||||||
this.selectedWorkspace = uid;
|
this.selectedWorkspace = uid;
|
||||||
},
|
},
|
||||||
async connectWorkspace (connection: ConnectionParams & { pgConnString?: string }, args?: {mode?: string; signal?: AbortSignal}) {
|
async connectWorkspace (connection: ConnectionParams & { connString?: string }, args?: {mode?: string; signal?: AbortSignal}) {
|
||||||
this.workspaces = (this.workspaces as Workspace[]).map(workspace => workspace.uid === connection.uid
|
this.workspaces = (this.workspaces as Workspace[]).map(workspace => workspace.uid === connection.uid
|
||||||
? {
|
? {
|
||||||
...workspace,
|
...workspace,
|
||||||
@ -427,7 +427,7 @@ export const useWorkspacesStore = defineStore('workspaces', {
|
|||||||
|
|
||||||
this.selectTab({ uid, tab: 0 });
|
this.selectTab({ uid, tab: 0 });
|
||||||
},
|
},
|
||||||
async switchConnection (connection: ConnectionParams & { pgConnString?: string }) {
|
async switchConnection (connection: ConnectionParams & { connString?: string }) {
|
||||||
await Connection.disconnect(connection.uid);
|
await Connection.disconnect(connection.uid);
|
||||||
return this.connectWorkspace(connection, { mode: 'switch' });
|
return this.connectWorkspace(connection, { mode: 'switch' });
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user