mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 10:16:00 +00:00
connecting via socket for mysql and postgres #358
This commit is contained in:
@@ -31,7 +31,20 @@ const drivers = driverBases.map(driverBase => ({
|
||||
...driverBase,
|
||||
analyserClass: Analyser,
|
||||
|
||||
async connect({ engine, server, port, user, password, database, databaseUrl, useDatabaseUrl, ssl, isReadOnly }) {
|
||||
async connect({
|
||||
engine,
|
||||
server,
|
||||
port,
|
||||
user,
|
||||
password,
|
||||
database,
|
||||
databaseUrl,
|
||||
useDatabaseUrl,
|
||||
ssl,
|
||||
isReadOnly,
|
||||
authType,
|
||||
socketPath,
|
||||
}) {
|
||||
let options = null;
|
||||
|
||||
if (engine == 'redshift@dbgate-plugin-postgres') {
|
||||
@@ -56,8 +69,8 @@ const drivers = driverBases.map(driverBase => ({
|
||||
connectionString: databaseUrl,
|
||||
}
|
||||
: {
|
||||
host: server,
|
||||
port,
|
||||
host: authType == 'socket' ? socketPath || driverBase.defaultSocketPath : server,
|
||||
port: authType == 'socket' ? null : port,
|
||||
user,
|
||||
password,
|
||||
database: database || 'postgres',
|
||||
@@ -65,6 +78,8 @@ const drivers = driverBases.map(driverBase => ({
|
||||
};
|
||||
}
|
||||
|
||||
console.log('OPTIONS', options);
|
||||
|
||||
const client = new pg.Client(options);
|
||||
await client.connect();
|
||||
|
||||
@@ -233,6 +248,19 @@ const drivers = driverBases.map(driverBase => ({
|
||||
const { rows } = await this.query(client, 'SELECT datname AS name FROM pg_database WHERE datistemplate = false');
|
||||
return rows;
|
||||
},
|
||||
|
||||
getAuthTypes() {
|
||||
return [
|
||||
{
|
||||
title: 'Host and port',
|
||||
name: 'hostPort',
|
||||
},
|
||||
{
|
||||
title: 'Socket',
|
||||
name: 'socket',
|
||||
},
|
||||
];
|
||||
},
|
||||
}));
|
||||
|
||||
module.exports = drivers;
|
||||
|
||||
@@ -115,7 +115,12 @@ const postgresDriverBase = {
|
||||
if (values.useDatabaseUrl) {
|
||||
return ['databaseUrl', 'isReadOnly'].includes(field);
|
||||
}
|
||||
return ['server', 'port', 'user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly'].includes(field);
|
||||
|
||||
return (
|
||||
['authType', 'user', 'password', 'defaultDatabase', 'singleDatabase', 'isReadOnly'].includes(field) ||
|
||||
(values.authType == 'socket' && ['socketPath'].includes(field)) ||
|
||||
(values.authType != 'socket' && ['server', 'port'].includes(field))
|
||||
);
|
||||
},
|
||||
|
||||
beforeConnectionSave: connection => {
|
||||
@@ -159,6 +164,10 @@ $$ LANGUAGE plpgsql;`,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
authTypeLabel: 'Connection mode',
|
||||
defaultAuthTypeName: 'hostPort',
|
||||
defaultSocketPath: '/var/run/postgresql',
|
||||
};
|
||||
|
||||
/** @type {import('dbgate-types').EngineDriver} */
|
||||
|
||||
Reference in New Issue
Block a user