mirror of
https://github.com/Spengreb/sync.git
synced 2026-05-17 13:02:05 +00:00
Add support for unix socket connections to the mysql database
This commit is contained in:
parent
adc0ea27a9
commit
9738c3f8c8
2 changed files with 20 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
# MySQL server details
|
# 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
|
# database: a MySQL database that the user specified has read/write access to
|
||||||
# user: username to authenticate as
|
# user: username to authenticate as
|
||||||
# password: password for user
|
# password: password for user
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,19 @@ let globalBanDB = null;
|
||||||
class Database {
|
class Database {
|
||||||
constructor(knexConfig = null) {
|
constructor(knexConfig = null) {
|
||||||
if (knexConfig === null) {
|
if (knexConfig === null) {
|
||||||
knexConfig = {
|
let mysqlServer = Config.get('mysql.server');
|
||||||
client: 'mysql',
|
let connection;
|
||||||
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'),
|
host: Config.get('mysql.server'),
|
||||||
port: Config.get('mysql.port'),
|
port: Config.get('mysql.port'),
|
||||||
user: Config.get('mysql.user'),
|
user: Config.get('mysql.user'),
|
||||||
|
|
@ -39,7 +49,12 @@ class Database {
|
||||||
database: Config.get('mysql.database'),
|
database: Config.get('mysql.database'),
|
||||||
multipleStatements: true, // Legacy thing
|
multipleStatements: true, // Legacy thing
|
||||||
charset: 'utf8mb4'
|
charset: 'utf8mb4'
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
knexConfig = {
|
||||||
|
client: 'mysql',
|
||||||
|
connection,
|
||||||
pool: {
|
pool: {
|
||||||
min: Config.get('mysql.pool-size'),
|
min: Config.get('mysql.pool-size'),
|
||||||
max: Config.get('mysql.pool-size')
|
max: Config.get('mysql.pool-size')
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue