import mysql from "serverless-mysql"; import grabDbSSL from "../grabDbSSL"; /** * # DSQL user read-only DB handler */ export default async function LOCAL_DB_HANDLER(...args: any[]) { 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(), }, onConnect: () => { console.log("Connection Successful!"); }, onConnectError: (/** @type {any} */ err: any) => { console.log("Connection Error", err.message); }, onError: (/** @type {any} */ err: any) => { console.log("Client Error", err.message); }, }); console.log("Querying ..."); try { const results = await MASTER.query(...args); await MASTER.end(); return JSON.parse(JSON.stringify(results)); } catch (/** @type {any} */ error: any) { console.log("DB Error =>", error.message); return { success: false, error: error.message, }; } }