dsql-admin/dsql-app/package-shared/utils/backend/global-db/DB_HANDLER.ts

28 lines
759 B
TypeScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
import mysql from "serverless-mysql";
import grabDSQLConnection from "../../grab-dsql-connection";
2025-01-13 08:00:21 +00:00
/**
* # DSQL user read-only DB handler
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
*/
export default async function DB_HANDLER(...args: any[]) {
2025-01-14 15:27:08 +00:00
const CONNECTION = grabDSQLConnection();
2025-01-13 08:00:21 +00:00
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();
}
}