mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 14:38:50 +00:00
refactor(db): rename serverReady variable
This commit is contained in:
1 parent
2ad0539107
commit
11b21f8ed2
4 files changed
+13
-13
No files matched your search
@@ -3,14 +3,14 @@ import { connectionOptions, mysql_transaction_isolation_level } from '../config'
|
||||
import { typeCast } from '../utils/typeCast';
|
||||
|
||||
let pool: Pool;
|
||||
let serverReady = false;
|
||||
let isServerConnected = false;
|
||||
|
||||
export async function waitForConnection() {
|
||||
if (!serverReady) {
|
||||
await new Promise<void>((resolve) => {
|
||||
if (!isServerConnected) {
|
||||
return await new Promise<boolean>((resolve) => {
|
||||
(function wait() {
|
||||
if (serverReady) {
|
||||
return resolve();
|
||||
if (isServerConnected) {
|
||||
return resolve(true);
|
||||
}
|
||||
setTimeout(wait);
|
||||
})();
|
||||
@@ -30,8 +30,8 @@ setTimeout(() => {
|
||||
pool.query(mysql_transaction_isolation_level, (err) => {
|
||||
if (err) return console.error(`^3Unable to establish a connection to the database!\n^3[${err}]^0`);
|
||||
console.log(`^2Database server connection established!^0`);
|
||||
serverReady = true;
|
||||
isServerConnected = true;
|
||||
});
|
||||
});
|
||||
|
||||
export { pool, serverReady };
|
||||
export { pool, isServerConnected };
|
||||
@@ -5,7 +5,7 @@ import { CFXCallback, CFXParameters } from '../types';
|
||||
import { parseResponse } from '../utils/parseResponse';
|
||||
import { executeType, parseExecute } from '../utils/parseExecute';
|
||||
import { scheduleTick } from '../utils/scheduleTick';
|
||||
import { serverReady, waitForConnection } from '../database';
|
||||
import { isServerConnected, waitForConnection } from '../database';
|
||||
|
||||
export const rawExecute = (
|
||||
invokingResource: string,
|
||||
@@ -28,7 +28,7 @@ export const rawExecute = (
|
||||
scheduleTick();
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!serverReady) await waitForConnection();
|
||||
if (!isServerConnected) await waitForConnection();
|
||||
|
||||
pool.getConnection((err, connection) => {
|
||||
if (err) return reject(err.message);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { pool, serverReady, waitForConnection } from '.';
|
||||
import { pool, isServerConnected, waitForConnection } from '.';
|
||||
import { parseArguments } from '../utils/parseArguments';
|
||||
import { parseResponse } from '../utils/parseResponse';
|
||||
import { logQuery } from '../logger';
|
||||
@@ -23,7 +23,7 @@ export const rawQuery = (
|
||||
scheduleTick();
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!serverReady) await waitForConnection();
|
||||
if (!isServerConnected) await waitForConnection();
|
||||
|
||||
pool.query(query, parameters, (err, result, _, executionTime) => {
|
||||
if (err) return reject(err);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { pool, serverReady, waitForConnection } from '.';
|
||||
import { pool, isServerConnected, waitForConnection } from '.';
|
||||
import { logQuery } from '../logger';
|
||||
import { CFXParameters, TransactionQuery } from '../types';
|
||||
import { parseTransaction } from '../utils/parseTransaction';
|
||||
@@ -15,7 +15,7 @@ export const rawTransaction = async (
|
||||
parameters: CFXParameters,
|
||||
callback?: (result: boolean) => void
|
||||
) => {
|
||||
if (!serverReady) await waitForConnection()
|
||||
if (!isServerConnected) await waitForConnection()
|
||||
|
||||
scheduleTick();
|
||||
|
||||
|
||||
Reference in new issue
Block a user