mirror of
https://github.com/mempool/mempool.git
synced 2025-01-01 03:04:27 +01:00
Merge pull request #1360 from dsbaars/feature/backend-unixsocket2
Add support for MySQL connections over UNIX sockets
This commit is contained in:
commit
4d9dfaa260
@ -44,6 +44,7 @@
|
|||||||
"ENABLED": true,
|
"ENABLED": true,
|
||||||
"HOST": "127.0.0.1",
|
"HOST": "127.0.0.1",
|
||||||
"PORT": 3306,
|
"PORT": 3306,
|
||||||
|
"SOCKET": "/var/run/mysql/mysql.sock",
|
||||||
"DATABASE": "mempool",
|
"DATABASE": "mempool",
|
||||||
"USERNAME": "mempool",
|
"USERNAME": "mempool",
|
||||||
"PASSWORD": "mempool"
|
"PASSWORD": "mempool"
|
||||||
|
@ -43,6 +43,7 @@ interface IConfig {
|
|||||||
DATABASE: {
|
DATABASE: {
|
||||||
ENABLED: boolean;
|
ENABLED: boolean;
|
||||||
HOST: string,
|
HOST: string,
|
||||||
|
SOCKET: string,
|
||||||
PORT: number;
|
PORT: number;
|
||||||
DATABASE: string;
|
DATABASE: string;
|
||||||
USERNAME: string;
|
USERNAME: string;
|
||||||
@ -121,6 +122,7 @@ const defaults: IConfig = {
|
|||||||
'DATABASE': {
|
'DATABASE': {
|
||||||
'ENABLED': true,
|
'ENABLED': true,
|
||||||
'HOST': '127.0.0.1',
|
'HOST': '127.0.0.1',
|
||||||
|
'SOCKET': '',
|
||||||
'PORT': 3306,
|
'PORT': 3306,
|
||||||
'DATABASE': 'mempool',
|
'DATABASE': 'mempool',
|
||||||
'USERNAME': 'mempool',
|
'USERNAME': 'mempool',
|
||||||
|
@ -1,17 +1,30 @@
|
|||||||
import config from './config';
|
import config from './config';
|
||||||
import { createPool, PoolConnection } from 'mysql2/promise';
|
import { createPool, PoolConnection } from 'mysql2/promise';
|
||||||
import logger from './logger';
|
import logger from './logger';
|
||||||
|
import { PoolOptions } from 'mysql2/typings/mysql';
|
||||||
|
|
||||||
export class DB {
|
export class DB {
|
||||||
static pool = createPool({
|
static poolConfig = ():PoolOptions => {
|
||||||
host: config.DATABASE.HOST,
|
let poolConfig:PoolOptions = {
|
||||||
port: config.DATABASE.PORT,
|
port: config.DATABASE.PORT,
|
||||||
database: config.DATABASE.DATABASE,
|
database: config.DATABASE.DATABASE,
|
||||||
user: config.DATABASE.USERNAME,
|
user: config.DATABASE.USERNAME,
|
||||||
password: config.DATABASE.PASSWORD,
|
password: config.DATABASE.PASSWORD,
|
||||||
connectionLimit: 10,
|
connectionLimit: 10,
|
||||||
supportBigNumbers: true,
|
supportBigNumbers: true,
|
||||||
});
|
timezone: '+00:00',
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.DATABASE.SOCKET !== "") {
|
||||||
|
poolConfig.socketPath = config.DATABASE.SOCKET;
|
||||||
|
} else {
|
||||||
|
poolConfig.host = config.DATABASE.HOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
return poolConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
static pool = createPool(DB.poolConfig());
|
||||||
|
|
||||||
static connectionsReady: number[] = [];
|
static connectionsReady: number[] = [];
|
||||||
|
|
||||||
|
3
contributors/dsbaars.txt
Normal file
3
contributors/dsbaars.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
I hereby accept the terms of the Contributor License Agreement in the CONTRIBUTING.md file of the mempool/mempool git repository as of January 25, 2022.
|
||||||
|
|
||||||
|
Signed: dsbaars
|
@ -41,6 +41,7 @@
|
|||||||
"DATABASE": {
|
"DATABASE": {
|
||||||
"ENABLED": __DATABASE_ENABLED__,
|
"ENABLED": __DATABASE_ENABLED__,
|
||||||
"HOST": "__DATABASE_HOST__",
|
"HOST": "__DATABASE_HOST__",
|
||||||
|
"SOCKET": "__DATABASE_SOCKET__",
|
||||||
"PORT": __DATABASE_PORT__,
|
"PORT": __DATABASE_PORT__,
|
||||||
"DATABASE": "__DATABASE_DATABASE__",
|
"DATABASE": "__DATABASE_DATABASE__",
|
||||||
"USERNAME": "__DATABASE_USERNAME__",
|
"USERNAME": "__DATABASE_USERNAME__",
|
||||||
|
@ -42,6 +42,7 @@ __SECOND_CORE_RPC_PASSWORD__=${SECOND_CORE_RPC_PASSWORD:=mempool}
|
|||||||
# DATABASE
|
# DATABASE
|
||||||
__DATABASE_ENABLED__=${DATABASE_ENABLED:=true}
|
__DATABASE_ENABLED__=${DATABASE_ENABLED:=true}
|
||||||
__DATABASE_HOST__=${DATABASE_HOST:=127.0.0.1}
|
__DATABASE_HOST__=${DATABASE_HOST:=127.0.0.1}
|
||||||
|
__DATABASE_SOCKET__=${DATABASE_SOCKET:=""}
|
||||||
__DATABASE_PORT__=${DATABASE_PORT:=3306}
|
__DATABASE_PORT__=${DATABASE_PORT:=3306}
|
||||||
__DATABASE_DATABASE__=${DATABASE_DATABASE:=mempool}
|
__DATABASE_DATABASE__=${DATABASE_DATABASE:=mempool}
|
||||||
__DATABASE_USERNAME__=${DATABASE_USERNAME:=mempool}
|
__DATABASE_USERNAME__=${DATABASE_USERNAME:=mempool}
|
||||||
@ -111,6 +112,8 @@ sed -i "s/__SECOND_CORE_RPC_PASSWORD__/${__SECOND_CORE_RPC_PASSWORD__}/g" mempoo
|
|||||||
|
|
||||||
sed -i "s/__DATABASE_ENABLED__/${__DATABASE_ENABLED__}/g" mempool-config.json
|
sed -i "s/__DATABASE_ENABLED__/${__DATABASE_ENABLED__}/g" mempool-config.json
|
||||||
sed -i "s/__DATABASE_HOST__/${__DATABASE_HOST__}/g" mempool-config.json
|
sed -i "s/__DATABASE_HOST__/${__DATABASE_HOST__}/g" mempool-config.json
|
||||||
|
sed -i "s!__DATABASE_SOCKET__!${__DATABASE_SOCKET__}!g" mempool-config.json
|
||||||
|
|
||||||
sed -i "s/__DATABASE_PORT__/${__DATABASE_PORT__}/g" mempool-config.json
|
sed -i "s/__DATABASE_PORT__/${__DATABASE_PORT__}/g" mempool-config.json
|
||||||
sed -i "s/__DATABASE_DATABASE__/${__DATABASE_DATABASE__}/g" mempool-config.json
|
sed -i "s/__DATABASE_DATABASE__/${__DATABASE_DATABASE__}/g" mempool-config.json
|
||||||
sed -i "s/__DATABASE_USERNAME__/${__DATABASE_USERNAME__}/g" mempool-config.json
|
sed -i "s/__DATABASE_USERNAME__/${__DATABASE_USERNAME__}/g" mempool-config.json
|
||||||
|
Loading…
Reference in New Issue
Block a user