datasquirel/package-shared/shell/utils/varDatabaseDbHandler.ts

65 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-01-10 19:10:28 +00:00
import dbHandler from "./dbHandler";
import { DSQL_TableSchemaType } from "../../types";
2024-12-06 10:31:24 +00:00
2025-01-10 19:10:28 +00:00
type Param = {
queryString: string;
queryValuesArray?: string[];
database?: string;
tableSchema?: DSQL_TableSchemaType;
};
2024-12-06 10:31:24 +00:00
/**
2025-01-10 19:10:28 +00:00
* # DB handler for specific database
2024-12-06 10:31:24 +00:00
*/
2025-01-10 19:10:28 +00:00
export default async function varDatabaseDbHandler({
2024-12-06 10:31:24 +00:00
queryString,
queryValuesArray,
database,
tableSchema,
2025-01-10 19:10:28 +00:00
}: Param): Promise<any> {
2024-12-06 10:31:24 +00:00
/**
* 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,
});
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
2025-01-10 19:10:28 +00:00
} catch (/** @type {any} */ error: any) {
2024-12-06 10:31:24 +00:00
console.log("Shell Vardb Error =>", error.message);
}
/**
* Return results
*
* @description Return results add to cache if "req" param is passed
*/
return results;
2025-01-10 19:10:28 +00:00
}