datasquirel/dist/package-shared/utils/backend/global-db/ROOT_DB_HANDLER.js
Benjamin Toby e9bb9fb07f Updates
2025-02-19 20:01:50 +01:00

41 lines
1.3 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = ROOT_DB_HANDLER;
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
/**
* # Root DB handler
*/
function ROOT_DB_HANDLER(...args) {
var _a;
const CONNECTION = (0, grab_dsql_connection_1.default)();
try {
return new Promise((resolve, reject) => {
CONNECTION.query(...args)
.then((results) => {
CONNECTION.end();
resolve(JSON.parse(JSON.stringify(results)));
})
.catch((err) => {
CONNECTION.end();
resolve({
error: err.message,
sql: err.sql,
});
});
});
}
catch (error) {
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `ROOT_DB_HANDLER Error`, error);
return {
success: false,
error: error.message,
};
}
finally {
CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end();
}
}