mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 06:28:54 +00:00
refactor(db): Delay connection until first tick
This commit is contained in:
1 parent
31d971837d
commit
6d96c1104b
2 files changed
+19
-16
No files matched your search
+18
-15
@@ -2,22 +2,25 @@ import { createPool, QueryError } from 'mysql2/promise';
|
||||
import { connectionOptions, mysql_transaction_isolation_level } from '../config';
|
||||
import { typeCast } from '../utils/typeCast';
|
||||
|
||||
const pool = createPool({
|
||||
connectTimeout: 60000,
|
||||
...connectionOptions,
|
||||
typeCast,
|
||||
});
|
||||
|
||||
let pool;
|
||||
let serverReady = false;
|
||||
|
||||
pool
|
||||
.query(mysql_transaction_isolation_level)
|
||||
.then(() => {
|
||||
console.log(`^2Database server connection established!^0`);
|
||||
serverReady = true;
|
||||
})
|
||||
.catch((e: QueryError) =>
|
||||
console.error(`^3Unable to establish a connection to the database! [${e.code}]\n${e.message}^0`)
|
||||
);
|
||||
setTimeout(() => {
|
||||
pool = createPool({
|
||||
connectTimeout: 60000,
|
||||
...connectionOptions,
|
||||
typeCast,
|
||||
});
|
||||
|
||||
pool
|
||||
.query(mysql_transaction_isolation_level)
|
||||
.then(() => {
|
||||
console.log(`^2Database server connection established!^0`);
|
||||
serverReady = true;
|
||||
})
|
||||
.catch((e: QueryError) =>
|
||||
console.error(`^3Unable to establish a connection to the database! [${e.code}]\n${e.message}^0`)
|
||||
);
|
||||
});
|
||||
|
||||
export { pool, serverReady };
|
||||
Reference in new issue
Block a user