mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-04 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';
|
import { typeCast } from '../utils/typeCast';
|
||||||
|
|
||||||
let pool: Pool;
|
let pool: Pool;
|
||||||
let serverReady = false;
|
let isServerConnected = false;
|
||||||
|
|
||||||
export async function waitForConnection() {
|
export async function waitForConnection() {
|
||||||
if (!serverReady) {
|
if (!isServerConnected) {
|
||||||
await new Promise<void>((resolve) => {
|
return await new Promise<boolean>((resolve) => {
|
||||||
(function wait() {
|
(function wait() {
|
||||||
if (serverReady) {
|
if (isServerConnected) {
|
||||||
return resolve();
|
return resolve(true);
|
||||||
}
|
}
|
||||||
setTimeout(wait);
|
setTimeout(wait);
|
||||||
})();
|
})();
|
||||||
@@ -30,8 +30,8 @@ setTimeout(() => {
|
|||||||
pool.query(mysql_transaction_isolation_level, (err) => {
|
pool.query(mysql_transaction_isolation_level, (err) => {
|
||||||
if (err) return console.error(`^3Unable to establish a connection to the database!\n^3[${err}]^0`);
|
if (err) return console.error(`^3Unable to establish a connection to the database!\n^3[${err}]^0`);
|
||||||
console.log(`^2Database server connection established!^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 { parseResponse } from '../utils/parseResponse';
|
||||||
import { executeType, parseExecute } from '../utils/parseExecute';
|
import { executeType, parseExecute } from '../utils/parseExecute';
|
||||||
import { scheduleTick } from '../utils/scheduleTick';
|
import { scheduleTick } from '../utils/scheduleTick';
|
||||||
import { serverReady, waitForConnection } from '../database';
|
import { isServerConnected, waitForConnection } from '../database';
|
||||||
|
|
||||||
export const rawExecute = (
|
export const rawExecute = (
|
||||||
invokingResource: string,
|
invokingResource: string,
|
||||||
@@ -28,7 +28,7 @@ export const rawExecute = (
|
|||||||
scheduleTick();
|
scheduleTick();
|
||||||
|
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (!serverReady) await waitForConnection();
|
if (!isServerConnected) await waitForConnection();
|
||||||
|
|
||||||
pool.getConnection((err, connection) => {
|
pool.getConnection((err, connection) => {
|
||||||
if (err) return reject(err.message);
|
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 { parseArguments } from '../utils/parseArguments';
|
||||||
import { parseResponse } from '../utils/parseResponse';
|
import { parseResponse } from '../utils/parseResponse';
|
||||||
import { logQuery } from '../logger';
|
import { logQuery } from '../logger';
|
||||||
@@ -23,7 +23,7 @@ export const rawQuery = (
|
|||||||
scheduleTick();
|
scheduleTick();
|
||||||
|
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
if (!serverReady) await waitForConnection();
|
if (!isServerConnected) await waitForConnection();
|
||||||
|
|
||||||
pool.query(query, parameters, (err, result, _, executionTime) => {
|
pool.query(query, parameters, (err, result, _, executionTime) => {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { pool, serverReady, waitForConnection } from '.';
|
import { pool, isServerConnected, waitForConnection } from '.';
|
||||||
import { logQuery } from '../logger';
|
import { logQuery } from '../logger';
|
||||||
import { CFXParameters, TransactionQuery } from '../types';
|
import { CFXParameters, TransactionQuery } from '../types';
|
||||||
import { parseTransaction } from '../utils/parseTransaction';
|
import { parseTransaction } from '../utils/parseTransaction';
|
||||||
@@ -15,7 +15,7 @@ export const rawTransaction = async (
|
|||||||
parameters: CFXParameters,
|
parameters: CFXParameters,
|
||||||
callback?: (result: boolean) => void
|
callback?: (result: boolean) => void
|
||||||
) => {
|
) => {
|
||||||
if (!serverReady) await waitForConnection()
|
if (!isServerConnected) await waitForConnection()
|
||||||
|
|
||||||
scheduleTick();
|
scheduleTick();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user