Add support for unix socket connections to the mysql database

This commit is contained in:
Zankaria 2024-09-19 15:59:46 +02:00 committed by Calvin Montgomery
parent adc0ea27a9
commit 9738c3f8c8
2 changed files with 20 additions and 5 deletions

View file

@ -1,5 +1,5 @@
# MySQL server details
# server: domain or IP of MySQL server
# server: domain, IP or unix socket path of MySQL server. If a unix socket, it be like so `unix:/path/to/sock.sock`
# database: a MySQL database that the user specified has read/write access to
# user: username to authenticate as
# password: password for user

View file

@ -29,9 +29,19 @@ let globalBanDB = null;
class Database {
constructor(knexConfig = null) {
if (knexConfig === null) {
knexConfig = {
client: 'mysql',
connection: {
let mysqlServer = Config.get('mysql.server');
let connection;
if (mysqlServer.startsWith('unix:')) {
connection = {
socketPath: mysqlServer.slice(5),
user: Config.get('mysql.user'),
password: Config.get('mysql.password'),
database: Config.get('mysql.database'),
multipleStatements: true, // Legacy thing
charset: 'utf8mb4'
}
} else {
connection = {
host: Config.get('mysql.server'),
port: Config.get('mysql.port'),
user: Config.get('mysql.user'),
@ -39,7 +49,12 @@ class Database {
database: Config.get('mysql.database'),
multipleStatements: true, // Legacy thing
charset: 'utf8mb4'
},
}
}
knexConfig = {
client: 'mysql',
connection,
pool: {
min: Config.get('mysql.pool-size'),
max: Config.get('mysql.pool-size')