dsql-admin/dsql-app/package-shared/utils/backend/global-db/DB_HANDLER.ts
Benjamin Toby e0a030f10d Updates
2025-01-13 09:00:21 +01:00

25 lines
658 B
TypeScript

/**
* # 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 = global.DSQL_DB_CONN;
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();
}
}