import mysql from "serverless-mysql"; import grabDbSSL from "../grabDbSSL"; const MASTER = mysql({ config: { host: process.env.DSQL_DB_HOST, user: process.env.DSQL_DB_USERNAME, password: process.env.DSQL_DB_PASSWORD, database: process.env.DSQL_DB_NAME, port: process.env.DSQL_DB_PORT ? Number(process.env.DSQL_DB_PORT) : undefined, charset: "utf8mb4", ssl: grabDbSSL(), }, }); /** * # DSQL user read-only DB handler */ export default async function DB_HANDLER(...args: any[]) { try { const results = await MASTER.query(...args); /** ********************* Clean up */ await MASTER.end(); return JSON.parse(JSON.stringify(results)); } catch (error: any) { console.log("DB Error =>", error); return { success: false, error: error.message, }; } }