Updates
This commit is contained in:
@@ -17,7 +17,7 @@ export default async function dbHandler({
|
||||
values,
|
||||
noErrorLogs,
|
||||
}: Param): Promise<any[] | object | null> {
|
||||
const CONNECTION = grabDSQLConnection();
|
||||
const CONNECTION = await grabDSQLConnection();
|
||||
|
||||
let results;
|
||||
|
||||
@@ -58,7 +58,11 @@ export default async function dbHandler({
|
||||
}
|
||||
|
||||
if (results) {
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
if (Array.isArray(results)) {
|
||||
return Array.from(results);
|
||||
} else {
|
||||
return results;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ export default async function fullAccessDbHandler({
|
||||
*/
|
||||
return error.message;
|
||||
} finally {
|
||||
DB_CONN?.end();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import fs from "fs";
|
||||
import serverError from "./serverError";
|
||||
import NO_DB_HANDLER from "../../utils/backend/global-db/NO_DB_HANDLER";
|
||||
|
||||
/**
|
||||
* # No Database DB Handler
|
||||
*/
|
||||
export default async function noDatabaseDbHandler(
|
||||
queryString: string
|
||||
): Promise<any> {
|
||||
process.env.NODE_ENV?.match(/dev/) &&
|
||||
fs.appendFileSync(
|
||||
"./.tmp/sqlQuery.sql",
|
||||
queryString + "\n" + Date() + "\n\n\n",
|
||||
"utf8"
|
||||
);
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
/** ********************* Run Query */
|
||||
results = await NO_DB_HANDLER(queryString);
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error: any) {
|
||||
serverError({
|
||||
component: "noDatabaseDbHandler",
|
||||
message: error.message,
|
||||
});
|
||||
|
||||
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
if (results) {
|
||||
return results;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,30 @@ export default async function suDbHandler({
|
||||
user,
|
||||
values,
|
||||
}: Params) {
|
||||
const connection = mariadb.createPool({
|
||||
const connection = await mariadb.createConnection({
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
user: process.env.DSQL_DB_USERNAME,
|
||||
password: process.env.DSQL_DB_PASSWORD,
|
||||
database: database,
|
||||
charset: "utf8mb4",
|
||||
ssl: grabDbSSL(),
|
||||
supportBigNumbers: true,
|
||||
bigNumberStrings: false,
|
||||
dateStrings: true,
|
||||
});
|
||||
|
||||
// const connection = mariadb.createPool({
|
||||
// host: process.env.DSQL_DB_HOST,
|
||||
// user: process.env.DSQL_DB_USERNAME,
|
||||
// password: process.env.DSQL_DB_PASSWORD,
|
||||
// database: database,
|
||||
// charset: "utf8mb4",
|
||||
// ssl: grabDbSSL(),
|
||||
// supportBigNumbers: true,
|
||||
// bigNumberStrings: false,
|
||||
// dateStrings: true,
|
||||
// });
|
||||
|
||||
const results = await connDbHandler(connection, query);
|
||||
|
||||
return results;
|
||||
|
||||
@@ -24,13 +24,16 @@ export default async function userDbHandler({
|
||||
const { fullName, host, username, password } =
|
||||
await grabMariadbMainUserForUser({ user });
|
||||
|
||||
const connection = mariadb.createPool({
|
||||
const connection = await mariadb.createConnection({
|
||||
host,
|
||||
user: username,
|
||||
password: password,
|
||||
database: database,
|
||||
charset: "utf8mb4",
|
||||
ssl: grabDbSSL(),
|
||||
supportBigNumbers: true,
|
||||
bigNumberStrings: false,
|
||||
dateStrings: true,
|
||||
});
|
||||
|
||||
const results = await connDbHandler(connection, query);
|
||||
|
||||
@@ -22,9 +22,11 @@ export default async function varDatabaseDbHandler({
|
||||
tableSchema,
|
||||
debug,
|
||||
}: Param): Promise<any> {
|
||||
let CONNECTION = grabDSQLConnection({ fa: true });
|
||||
if (global.DSQL_USE_LOCAL) CONNECTION = grabDSQLConnection({ local: true });
|
||||
if (database?.match(/^datasquirel$/)) CONNECTION = grabDSQLConnection();
|
||||
let CONNECTION = await grabDSQLConnection({ fa: true });
|
||||
if (global.DSQL_USE_LOCAL)
|
||||
CONNECTION = await grabDSQLConnection({ local: true });
|
||||
if (database?.match(/^datasquirel$/))
|
||||
CONNECTION = await grabDSQLConnection();
|
||||
|
||||
if (debug) {
|
||||
console.log(`varDatabaseDbHandler:query:`, queryString);
|
||||
|
||||
@@ -38,7 +38,6 @@ export default async function varReadOnlyDatabaseDbHandler({
|
||||
|
||||
return error.message;
|
||||
} finally {
|
||||
DB_CONN?.end();
|
||||
}
|
||||
|
||||
if (results) {
|
||||
|
||||
Reference in New Issue
Block a user