mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
#191 postgre - ability to define connection by connection string
This commit is contained in:
parent
1d90cd25c4
commit
f68744fba7
@ -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);
|
||||
|
@ -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: '',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user