mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 21:15:59 +00:00
#191 postgre - ability to define connection by connection string
This commit is contained in:
@@ -27,7 +27,7 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
...driverBase,
|
...driverBase,
|
||||||
analyserClass: Analyser,
|
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;
|
let options = null;
|
||||||
|
|
||||||
if (engine == 'redshift@dbgate-plugin-postgres') {
|
if (engine == 'redshift@dbgate-plugin-postgres') {
|
||||||
@@ -47,15 +47,18 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
connectionString: url,
|
connectionString: url,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
options = {
|
options = useDatabaseUrl
|
||||||
// connectionString: 'postgres://root@localhost:26257/postgres?sslmode=disabke'
|
? {
|
||||||
host: server,
|
connectionString: databaseUrl,
|
||||||
port,
|
}
|
||||||
user,
|
: {
|
||||||
password,
|
host: server,
|
||||||
database: database || 'postgres',
|
port,
|
||||||
ssl,
|
user,
|
||||||
};
|
password,
|
||||||
|
database: database || 'postgres',
|
||||||
|
ssl,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new pg.Client(options);
|
const client = new pg.Client(options);
|
||||||
|
|||||||
@@ -38,10 +38,35 @@ const postgresDriverBase = {
|
|||||||
...driverBase,
|
...driverBase,
|
||||||
dumperClass: Dumper,
|
dumperClass: Dumper,
|
||||||
dialect,
|
dialect,
|
||||||
showConnectionField: (field, values) =>
|
// showConnectionField: (field, values) =>
|
||||||
['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field),
|
// ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase'].includes(field),
|
||||||
getQuerySplitterOptions: () => postgreSplitterOptions,
|
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: {
|
__analyserInternals: {
|
||||||
refTableCond: '',
|
refTableCond: '',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user