dsql-admin/dsql-app/package-shared/functions/backend/noDatabaseDbHandler.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
import fs from "fs";
import serverError from "./serverError";
2025-01-14 06:10:36 +00:00
import NO_DB_HANDLER from "../../utils/backend/global-db/NO_DB_HANDLER";
2024-11-05 11:12:42 +00:00
/**
2025-01-13 08:00:21 +00:00
* # No Database DB Handler
2024-11-05 11:12:42 +00:00
*/
2025-01-13 08:00:21 +00:00
export default async function noDatabaseDbHandler(
queryString: string
): Promise<any> {
2024-11-05 11:12:42 +00:00
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);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
2025-01-13 08:00:21 +00:00
} catch (/** @type {any} */ error: any) {
2024-11-05 11:12:42 +00:00
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;
}
2025-01-13 08:00:21 +00:00
}