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

27 lines
747 B
TypeScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
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) {
2025-02-19 19:38:56 +00:00
global.ERROR_CALLBACK?.(`DB_HANDLER Error`, error as Error);
2025-01-13 08:00:21 +00:00
return {
success: false,
error: error.message,
};
} finally {
await CONNECTION?.end();
}
}