dsql-admin/dsql-app/package-shared/utils/backend/global-db/DB_HANDLER.ts
Benjamin Toby 81cf010cb5 Updates
2025-01-14 16:27:08 +01:00

28 lines
759 B
TypeScript

import mysql from "serverless-mysql";
import grabDSQLConnection from "../../grab-dsql-connection";
/**
* # DSQL user read-only DB handler
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
*/
export default async function DB_HANDLER(...args: any[]) {
const CONNECTION = grabDSQLConnection();
try {
if (!CONNECTION)
throw new Error("No Connection provided to DB_HANDLER function!");
const results = await CONNECTION.query(...args);
return JSON.parse(JSON.stringify(results));
} catch (error: any) {
console.log("DB Error =>", error);
return {
success: false,
error: error.message,
};
} finally {
await CONNECTION?.end();
}
}