mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-04 06:28:53 +00:00
refactor(db): Delay connection until first tick
This commit is contained in:
1 parent
31d971837d
commit
6d96c1104b
2 files changed
+9
-6
No files matched your search
+1
-1
@@ -3,7 +3,7 @@ game 'common'
|
|||||||
|
|
||||||
name 'oxmysql'
|
name 'oxmysql'
|
||||||
description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.'
|
description 'Database wrapper for FiveM utilising node-mysql2 offering improved performance and security.'
|
||||||
version '2.0.2'
|
version '2.0.3'
|
||||||
url 'https://github.com/overextended/oxmysql'
|
url 'https://github.com/overextended/oxmysql'
|
||||||
author 'overextended'
|
author 'overextended'
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,17 @@ import { createPool, QueryError } from 'mysql2/promise';
|
|||||||
import { connectionOptions, mysql_transaction_isolation_level } from '../config';
|
import { connectionOptions, mysql_transaction_isolation_level } from '../config';
|
||||||
import { typeCast } from '../utils/typeCast';
|
import { typeCast } from '../utils/typeCast';
|
||||||
|
|
||||||
const pool = createPool({
|
let pool;
|
||||||
|
let serverReady = false;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
pool = createPool({
|
||||||
connectTimeout: 60000,
|
connectTimeout: 60000,
|
||||||
...connectionOptions,
|
...connectionOptions,
|
||||||
typeCast,
|
typeCast,
|
||||||
});
|
});
|
||||||
|
|
||||||
let serverReady = false;
|
pool
|
||||||
|
|
||||||
pool
|
|
||||||
.query(mysql_transaction_isolation_level)
|
.query(mysql_transaction_isolation_level)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`^2Database server connection established!^0`);
|
console.log(`^2Database server connection established!^0`);
|
||||||
@@ -19,5 +21,6 @@ pool
|
|||||||
.catch((e: QueryError) =>
|
.catch((e: QueryError) =>
|
||||||
console.error(`^3Unable to establish a connection to the database! [${e.code}]\n${e.message}^0`)
|
console.error(`^3Unable to establish a connection to the database! [${e.code}]\n${e.message}^0`)
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
|
||||||
export { pool, serverReady };
|
export { pool, serverReady };
|
||||||
Reference in new issue
Block a user