connecting via socket for mysql and postgres #358

This commit is contained in:
Jan Prochazka
2022-09-08 14:23:13 +02:00
parent 5eda39cb62
commit 0293766bad
7 changed files with 84 additions and 14 deletions

View File

@@ -29,10 +29,11 @@ const drivers = driverBases.map(driverBase => ({
...driverBase,
analyserClass: Analyser,
async connect({ server, port, user, password, database, ssl, isReadOnly, forceRowsAsObjects }) {
const connection = mysql2.createConnection({
host: server,
port,
async connect({ server, port, user, password, database, ssl, isReadOnly, forceRowsAsObjects, socketPath, authType }) {
const options = {
host: authType == 'socket' ? null : server,
port: authType == 'socket' ? null : port,
socketPath: authType == 'socket' ? socketPath || driverBase.defaultSocketPath : null,
user,
password,
database,
@@ -43,7 +44,9 @@ const drivers = driverBases.map(driverBase => ({
dateStrings: true,
// TODO: test following options
// multipleStatements: true,
});
};
const connection = mysql2.createConnection(options);
connection._database_name = database;
if (isReadOnly) {
await this.query(connection, 'SET SESSION TRANSACTION READ ONLY');
@@ -182,6 +185,20 @@ const drivers = driverBases.map(driverBase => ({
});
return res;
},
getAuthTypes() {
return [
{
title: 'Host and port',
name: 'hostPort',
disabledFields: ['socketPath'],
},
{
title: 'Socket',
name: 'socket',
disabledFields: ['server', 'port'],
},
];
},
}));
module.exports = drivers;