#191 postgre - ability to define connection by connection string

This commit is contained in:
Jan Prochazka 2021-11-14 18:45:32 +01:00
parent 1d90cd25c4
commit f68744fba7
2 changed files with 40 additions and 12 deletions

View File

@ -27,7 +27,7 @@ const drivers = driverBases.map(driverBase => ({
...driverBase,
analyserClass: Analyser,
async connect({ engine, server, port, user, password, database, databaseUrl, ssl }) {
async connect({ engine, server, port, user, password, database, databaseUrl, useDatabaseUrl, ssl }) {
let options = null;
if (engine == 'redshift@dbgate-plugin-postgres') {
@ -47,15 +47,18 @@ const drivers = driverBases.map(driverBase => ({
connectionString: url,
};
} else {
options = {
// connectionString: 'postgres://root@localhost:26257/postgres?sslmode=disabke'
host: server,
port,
user,
password,
database: database || 'postgres',
ssl,
};
options = useDatabaseUrl
? {
connectionString: databaseUrl,
}
: {
host: server,
port,
user,
password,
database: database || 'postgres',
ssl,
};
}
const client = new pg.Client(options);

View File

@ -38,10 +38,35 @@ const postgresDriverBase = {
...driverBase,
dumperClass: Dumper,
dialect,
showConnectionField: (field, values) =>
['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field),
// showConnectionField: (field, values) =>
// ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field),
getQuerySplitterOptions: () => postgreSplitterOptions,
databaseUrlPlaceholder: 'e.g. postgresql://user:password@localhost:5432/default_database',
showConnectionField: (field, values) => {
if (field == 'useDatabaseUrl') return true;
if (values.useDatabaseUrl) {
return ['databaseUrl', 'defaultDatabase', 'singleDatabase'].includes(field);
}
return ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field);
},
beforeConnectionSave: connection => {
const { databaseUrl } = connection;
if (databaseUrl) {
const m = databaseUrl.match(/\/([^/]+)($|\?)/);
if (m) {
return {
...connection,
singleDatabase: true,
defaultDatabase: m[1],
};
}
}
return connection;
},
__analyserInternals: {
refTableCond: '',
},