mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 06:28:53 +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 { connectionOptions, mysql_transaction_isolation_level, setDebug } from '../config';
|
||||||
import { profilerStatements } from '../logger';
|
|
||||||
|
|
||||||
let pool: Pool;
|
let pool: Pool;
|
||||||
let isServerConnected = false;
|
let isServerConnected = false;
|
||||||
|
let dbVersion = '';
|
||||||
|
|
||||||
export async function waitForConnection() {
|
export async function waitForConnection() {
|
||||||
if (!isServerConnected) {
|
if (!isServerConnected) {
|
||||||
@@ -35,8 +35,12 @@ setTimeout(async () => {
|
|||||||
setConnectionPool();
|
setConnectionPool();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
(await pool.getConnection()).release();
|
const connection = await pool.getConnection();
|
||||||
console.log(`^2Database server connection established!^0`);
|
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;
|
isServerConnected = true;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.log(
|
console.log(
|
||||||
@@ -45,4 +49,4 @@ setTimeout(async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export { pool, isServerConnected };
|
export { pool, isServerConnected, dbVersion };
|
||||||
Reference in new issue
Block a user