mirror of
https://github.com/mempool/mempool.git
synced 2024-12-29 01:34:28 +01:00
ec12f21113
* Backend: Bumping Typescript version to 4.4.2 * Replacing any types with instanceOf checks.
27 lines
716 B
TypeScript
27 lines
716 B
TypeScript
import config from './config';
|
|
import { createPool } from 'mysql2/promise';
|
|
import logger from './logger';
|
|
|
|
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,
|
|
});
|
|
}
|
|
|
|
export async function checkDbConnection() {
|
|
try {
|
|
const connection = await DB.pool.getConnection();
|
|
logger.info('Database connection established.');
|
|
connection.release();
|
|
} catch (e) {
|
|
logger.err('Could not connect to database: ' + (e instanceof Error ? e.message : e));
|
|
process.exit(1);
|
|
}
|
|
}
|