mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 22:21:51 +00:00
refactor(database): output db version in connection message
This commit is contained in:
1 parent
f3401eb671
commit
11b7433398
1 file changed
+9
-5
@@ -1,9 +1,9 @@
|
||||
import { createPool, Pool } from 'mysql2/promise';
|
||||
import { createPool, Pool, RowDataPacket } from 'mysql2/promise';
|
||||
import { connectionOptions, mysql_transaction_isolation_level, setDebug } from '../config';
|
||||
import { profilerStatements } from '../logger';
|
||||
|
||||
let pool: Pool;
|
||||
let isServerConnected = false;
|
||||
let dbVersion = '';
|
||||
|
||||
export async function waitForConnection() {
|
||||
if (!isServerConnected) {
|
||||
@@ -35,8 +35,12 @@ setTimeout(async () => {
|
||||
setConnectionPool();
|
||||
|
||||
try {
|
||||
(await pool.getConnection()).release();
|
||||
console.log(`^2Database server connection established!^0`);
|
||||
const connection = await pool.getConnection();
|
||||
const [result] = await <Promise<RowDataPacket[]>> connection.query('SELECT VERSION() as version')
|
||||
dbVersion = `^5[${result[0].version}]`
|
||||
connection.release();
|
||||
|
||||
console.log(`${dbVersion} ^2Database server connection established!^0`);
|
||||
isServerConnected = true;
|
||||
} catch (err: any) {
|
||||
console.log(
|
||||
@@ -45,4 +49,4 @@ setTimeout(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
export { pool, isServerConnected };
|
||||
export { pool, isServerConnected, dbVersion };
|
||||
Reference in new issue
Block a user