mempool/backend/src/database.ts
softsimon ec12f21113
Backend: Bumping Typescript version to 4.4.2 (#748)
* Backend: Bumping Typescript version to 4.4.2

* Replacing any types with instanceOf checks.
2021-08-31 15:09:33 +03:00

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);
}
}