mirror of
https://github.com/mempool/mempool.git
synced 2025-01-04 20:54:26 +01:00
27 lines
645 B
TypeScript
27 lines
645 B
TypeScript
|
const config = require('../mempool-config.json');
|
||
|
import { createPool } from 'mysql2/promise';
|
||
|
|
||
|
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();
|
||
|
console.log('MySQL connection established.');
|
||
|
connection.release();
|
||
|
} catch (e) {
|
||
|
console.log('Could not connect to MySQL.');
|
||
|
console.log(e);
|
||
|
process.exit(1);
|
||
|
}
|
||
|
}
|