import dbHandler from "./dbHandler";
import { DSQL_TableSchemaType } from "../../types";

type Param = {
    queryString: string;
    queryValuesArray?: string[];
};

/**
 * # DB handler for specific database
 */
export default async function varDatabaseDbHandler({
    queryString,
    queryValuesArray,
}: 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,
            });
        } else {
            results = await dbHandler({
                query: queryString,
            });
        }

        ////////////////////////////////////////
        ////////////////////////////////////////
        ////////////////////////////////////////
    } 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;
}
