// @ts-check import fs from "fs"; import serverError from "./serverError"; import parseDbResults from "./parseDbResults"; import DSQL_USER_DB_HANDLER from "../../utils/backend/global-db/DSQL_USER_DB_HANDLER"; import LOCAL_DB_HANDLER from "../../utils/backend/global-db/LOCAL_DB_HANDLER"; type Param = { queryString: string; database: string; queryValuesArray?: string[]; tableSchema?: import("../../types").DSQL_TableSchemaType; useLocal?: boolean; }; /** * # Read Only Db Handler with Varaibles * @returns */ export default async function varReadOnlyDatabaseDbHandler({ queryString, database, queryValuesArray, tableSchema, useLocal, }: Param) { /** * Declare variables * * @description Declare "results" variable */ let results; /** * Fetch from db * * @description Fetch data from db if no cache */ try { results = useLocal ? await LOCAL_DB_HANDLER(queryString, queryValuesArray) : await DSQL_USER_DB_HANDLER({ paradigm: "Read Only", database, queryString, queryValues: queryValuesArray, }); //////////////////////////////////////// } catch (/** @type {any} */ error: any) { //////////////////////////////////////// serverError({ component: "varReadOnlyDatabaseDbHandler", message: error.message, noMail: true, }); /** * Return error */ return error.message; } /** * Return results * * @description Return results add to cache if "req" param is passed */ if (results) { const unparsedResults = results; const parsedResults = await parseDbResults({ unparsedResults: unparsedResults, tableSchema: tableSchema, }); return parsedResults; } else { return null; } }