Add MySQL socket support
This commit is contained in:
		
							parent
							
								
									ee5210acc4
								
							
						
					
					
						commit
						bc729dc6f4
					
				@ -43,6 +43,7 @@ interface IConfig {
 | 
			
		||||
  DATABASE: {
 | 
			
		||||
    ENABLED: boolean;
 | 
			
		||||
    HOST: string,
 | 
			
		||||
    SOCKET: string | undefined,
 | 
			
		||||
    PORT: number;
 | 
			
		||||
    DATABASE: string;
 | 
			
		||||
    USERNAME: string;
 | 
			
		||||
@ -121,6 +122,7 @@ const defaults: IConfig = {
 | 
			
		||||
  'DATABASE': {
 | 
			
		||||
    'ENABLED': true,
 | 
			
		||||
    'HOST': '127.0.0.1',
 | 
			
		||||
    'SOCKET': undefined,
 | 
			
		||||
    'PORT': 3306,
 | 
			
		||||
    'DATABASE': 'mempool',
 | 
			
		||||
    'USERNAME': 'mempool',
 | 
			
		||||
 | 
			
		||||
@ -1,17 +1,29 @@
 | 
			
		||||
import config from './config';
 | 
			
		||||
import { createPool, PoolConnection } from 'mysql2/promise';
 | 
			
		||||
import logger from './logger';
 | 
			
		||||
import { PoolOptions } from 'mysql2/typings/mysql';
 | 
			
		||||
 | 
			
		||||
export class DB {
 | 
			
		||||
  static pool = createPool({
 | 
			
		||||
    host: config.DATABASE.HOST,
 | 
			
		||||
    port: config.DATABASE.PORT,
 | 
			
		||||
    database: config.DATABASE.DATABASE,
 | 
			
		||||
    user: config.DATABASE.USERNAME,
 | 
			
		||||
    password: config.DATABASE.PASSWORD,
 | 
			
		||||
    connectionLimit: 10,
 | 
			
		||||
    supportBigNumbers: true,
 | 
			
		||||
  });
 | 
			
		||||
  static poolConfig = ():PoolOptions => {
 | 
			
		||||
    let poolConfig:PoolOptions = {
 | 
			
		||||
      port: config.DATABASE.PORT,
 | 
			
		||||
      database: config.DATABASE.DATABASE,
 | 
			
		||||
      user: config.DATABASE.USERNAME,
 | 
			
		||||
      password: config.DATABASE.PASSWORD,
 | 
			
		||||
      connectionLimit: 10,
 | 
			
		||||
      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[] = [];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -41,6 +41,7 @@
 | 
			
		||||
  "DATABASE": {
 | 
			
		||||
    "ENABLED": __DATABASE_ENABLED__,
 | 
			
		||||
    "HOST": "__DATABASE_HOST__",
 | 
			
		||||
    "SOCKET": "__DATABASE_SOCKET__",
 | 
			
		||||
    "PORT": __DATABASE_PORT__,
 | 
			
		||||
    "DATABASE": "__DATABASE_DATABASE__",
 | 
			
		||||
    "USERNAME": "__DATABASE_USERNAME__",
 | 
			
		||||
 | 
			
		||||
@ -42,6 +42,7 @@ __SECOND_CORE_RPC_PASSWORD__=${SECOND_CORE_RPC_PASSWORD:=mempool}
 | 
			
		||||
# DATABASE
 | 
			
		||||
__DATABASE_ENABLED__=${DATABASE_ENABLED:=true}
 | 
			
		||||
__DATABASE_HOST__=${DATABASE_HOST:=127.0.0.1}
 | 
			
		||||
__DATABASE_SOCKET__=${DATABASE_SOCKET:=""}
 | 
			
		||||
__DATABASE_PORT__=${DATABASE_PORT:=3306}
 | 
			
		||||
__DATABASE_DATABASE__=${DATABASE_DATABASE:=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_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_DATABASE__/${__DATABASE_DATABASE__}/g" mempool-config.json
 | 
			
		||||
sed -i "s/__DATABASE_USERNAME__/${__DATABASE_USERNAME__}/g" mempool-config.json
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user