Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 31de350

Browse files
committed
fix(db/pool): set pool after confirming a connection
1 parent e6140e8 commit 31de350

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/database/pool.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@ export async function createConnectionPool() {
1010
const config = getConnectionOptions();
1111

1212
try {
13-
pool = createPool(config);
13+
const dbPool = createPool(config);
1414

15-
pool.on('connection', (connection) => {
15+
dbPool.on('connection', (connection) => {
1616
connection.query(mysql_transaction_isolation_level);
1717
});
1818

1919
using conn = await getConnection();
20-
21-
const result = await conn.query('SELECT VERSION() as version') as RowDataPacket[];
20+
21+
const result = (await conn.query('SELECT VERSION() as version')) as RowDataPacket[];
2222
dbVersion = `^5[${result[0].version}]`;
2323

2424
console.log(`${dbVersion} ^2Database server connection established!^0`);
2525

2626
if (config.multipleStatements) {
27-
console.warn(`multipleStatements is enabled. Used incorrectly, this option may cause SQL injection.`)
27+
console.warn(`multipleStatements is enabled. Used incorrectly, this option may cause SQL injection.`);
2828
}
29-
29+
30+
pool = dbPool;
3031
} catch (err: any) {
3132
const message = err.message.includes('auth_gssapi_client')
3233
? `Requested authentication using unknown plugin auth_gssapi_client.`
@@ -38,7 +39,7 @@ export async function createConnectionPool() {
3839
}: ${message}^0`
3940
);
4041

41-
console.log(`See https://github.com/overextended/oxmysql/issues/154 for more information.`)
42+
console.log(`See https://github.com/overextended/oxmysql/issues/154 for more information.`);
4243

4344
if (config.password) config.password = '******';
4445

0 commit comments

Comments
 (0)