mempool/backend/src/database.ts

27 lines
661 B
TypeScript
Raw Normal View History

2019-07-21 16:59:47 +02:00
const config = require('../mempool-config.json');
import { createPool } from 'mysql2/promise';
import logger from './logger';
2019-07-21 16:59:47 +02:00
export class DB {
static pool = createPool({
host: config.DB_HOST,
port: config.DB_PORT,
database: config.DB_DATABASE,
user: config.DB_USER,
password: config.DB_PASSWORD,
connectionLimit: 10,
supportBigNumbers: true,
});
}
export async function checkDbConnection() {
try {
const connection = await DB.pool.getConnection();
logger.info('Database connection established.');
2019-07-21 16:59:47 +02:00
connection.release();
} catch (e) {
logger.err('Could not connect to database.');
2019-07-21 16:59:47 +02:00
process.exit(1);
}
}