datasquirel/package-shared/shell/utils/varDatabaseDbHandler.ts
2025-01-10 20:10:28 +01:00

65 lines
1.5 KiB
TypeScript
Executable File

import dbHandler from "./dbHandler";
import { DSQL_TableSchemaType } from "../../types";
type Param = {
queryString: string;
queryValuesArray?: string[];
database?: string;
tableSchema?: DSQL_TableSchemaType;
};
/**
* # DB handler for specific database
*/
export default async function varDatabaseDbHandler({
queryString,
queryValuesArray,
database,
tableSchema,
}: Param): Promise<any> {
/**
* Declare variables
*
* @description Declare "results" variable
*/
let results;
/**
* Fetch from db
*
* @description Fetch data from db if no cache
*/
try {
if (
queryString &&
queryValuesArray &&
Array.isArray(queryValuesArray) &&
queryValuesArray[0]
) {
results = await dbHandler({
query: queryString,
values: queryValuesArray,
database,
});
} else {
results = await dbHandler({
query: queryString,
database,
});
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} catch (/** @type {any} */ error: any) {
console.log("Shell Vardb Error =>", error.message);
}
/**
* Return results
*
* @description Return results add to cache if "req" param is passed
*/
return results;
}