This commit is contained in:
Benjamin Toby
2025-01-14 11:14:50 +01:00
parent edd555c088
commit d55fe64d47
30 changed files with 225 additions and 481 deletions
+2 -13
View File
@@ -13,25 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = DB_HANDLER;
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
/**
* # DSQL user read-only DB handler
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
*/
function DB_HANDLER(...args) {
return __awaiter(this, void 0, void 0, function* () {
const CONNECTION = (0, serverless_mysql_1.default)({
config: {
host: process.env.DSQL_DB_HOST,
user: process.env.DSQL_DB_USERNAME,
password: process.env.DSQL_DB_PASSWORD,
database: process.env.DSQL_DB_NAME,
port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined,
charset: "utf8mb4",
},
});
const CONNECTION = (0, grab_dsql_connection_1.default)();
try {
if (!CONNECTION)
throw new Error("No Connection provided to DB_HANDLER function!");
@@ -13,36 +13,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = DSQL_USER_DB_HANDLER;
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const conn_db_handler_1 = __importDefault(require("../../db/conn-db-handler"));
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
/**
* # DSQL user read-only DB handler
*/
function DSQL_USER_DB_HANDLER(_a) {
return __awaiter(this, arguments, void 0, function* ({ paradigm, queryString, queryValues, }) {
const CONNECTION = paradigm == "Read Only"
? (0, serverless_mysql_1.default)({
config: {
host: process.env.DSQL_DB_HOST,
user: process.env.DSQL_DB_READ_ONLY_USERNAME,
password: process.env.DSQL_DB_READ_ONLY_PASSWORD,
port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined,
charset: "utf8mb4",
},
})
: (0, serverless_mysql_1.default)({
config: {
host: process.env.DSQL_DB_HOST,
user: process.env.DSQL_DB_FULL_ACCESS_USERNAME,
password: process.env.DSQL_DB_FULL_ACCESS_PASSWORD,
port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined,
charset: "utf8mb4",
},
});
? (0, grab_dsql_connection_1.default)({ ro: true })
: (0, grab_dsql_connection_1.default)({ fa: true });
try {
return yield (0, conn_db_handler_1.default)(CONNECTION, queryString, queryValues);
}
@@ -53,85 +33,5 @@ function DSQL_USER_DB_HANDLER(_a) {
finally {
CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end();
}
// try {
// return new Promise((resolve, reject) => {
// const fullAccess = paradigm?.match(/full.access|^fa$/i)
// ? true
// : false;
// try {
// if (fullAccess) {
// DSQL_USER = mysql({
// config: {
// host: process.env.DSQL_DB_HOST,
// user: process.env.DSQL_DB_FULL_ACCESS_USERNAME,
// password: process.env.DSQL_DB_FULL_ACCESS_PASSWORD,
// database: database,
// ssl: grabDbSSL(),
// },
// });
// } else {
// DSQL_USER = mysql({
// config: {
// host: process.env.DSQL_DB_HOST,
// user: process.env.DSQL_DB_READ_ONLY_USERNAME,
// password: process.env.DSQL_DB_READ_ONLY_PASSWORD,
// database: database,
// ssl: grabDbSSL(),
// },
// });
// }
// /**
// * ### Run query Function
// * @param {any} results
// */
// function runQuery(results: any) {
// DSQL_USER.end();
// resolve(JSON.parse(JSON.stringify(results)));
// }
// /**
// * ### Query Error
// * @param {any} err
// */
// function queryError(err: any) {
// DSQL_USER.end();
// resolve({
// error: err.message,
// queryStringGenerated: queryString,
// queryValuesGenerated: queryValues,
// sql: err.sql,
// });
// }
// if (
// queryValues &&
// Array.isArray(queryValues) &&
// queryValues[0]
// ) {
// DSQL_USER.query(queryString, queryValues)
// .then(runQuery)
// .catch(queryError);
// } else {
// DSQL_USER.query(queryString)
// .then(runQuery)
// .catch(queryError);
// }
// ////////////////////////////////////////
// } catch (/** @type {any} */ error: any) {
// ////////////////////////////////////////
// fs.appendFileSync(
// "./.tmp/dbErrorLogs.txt",
// error.message + "\n" + Date() + "\n\n\n",
// "utf8"
// );
// resolve({
// error: error.message,
// });
// }
// });
// } catch (/** @type {any} */ error: any) {
// return {
// success: false,
// error: error.message,
// };
// }
});
}
@@ -13,47 +13,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = LOCAL_DB_HANDLER;
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const grabDbSSL_1 = __importDefault(require("../grabDbSSL"));
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
/**
* # DSQL user read-only DB handler
*/
function LOCAL_DB_HANDLER(...args) {
return __awaiter(this, void 0, void 0, function* () {
const MASTER = (0, serverless_mysql_1.default)({
config: {
host: process.env.DSQL_DB_HOST,
user: process.env.DSQL_DB_USERNAME,
password: process.env.DSQL_DB_PASSWORD,
database: process.env.DSQL_DB_NAME,
port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined,
charset: "utf8mb4",
ssl: (0, grabDbSSL_1.default)(),
},
onConnect: () => {
console.log("Connection Successful!");
},
onConnectError: (/** @type {any} */ err) => {
console.log("Connection Error", err.message);
},
onError: (/** @type {any} */ err) => {
console.log("Client Error", err.message);
},
});
const MASTER = (0, grab_dsql_connection_1.default)();
console.log("Querying ...");
try {
const results = yield MASTER.query(...args);
yield MASTER.end();
return JSON.parse(JSON.stringify(results));
}
catch ( /** @type {any} */error) {
catch (error) {
console.log("DB Error =>", error.message);
return {
success: false,
error: error.message,
};
}
finally {
yield (MASTER === null || MASTER === void 0 ? void 0 : MASTER.end());
}
});
}
@@ -4,23 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = NO_DB_HANDLER;
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
/**
* # DSQL user read-only DB handler
*/
function NO_DB_HANDLER(...args) {
const CONNECTION = (0, serverless_mysql_1.default)({
config: {
host: process.env.DSQL_DB_HOST,
user: process.env.DSQL_DB_USERNAME,
password: process.env.DSQL_DB_PASSWORD,
database: process.env.DSQL_DB_NAME,
port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined,
charset: "utf8mb4",
},
});
const CONNECTION = (0, grab_dsql_connection_1.default)();
try {
return new Promise((resolve, reject) => {
CONNECTION.query(...args)
@@ -4,23 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = ROOT_DB_HANDLER;
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const grab_dsql_connection_1 = __importDefault(require("../../grab-dsql-connection"));
/**
* # Root DB handler
*/
function ROOT_DB_HANDLER(...args) {
const CONNECTION = (0, serverless_mysql_1.default)({
config: {
host: process.env.DSQL_DB_HOST,
user: process.env.DSQL_DB_USERNAME,
password: process.env.DSQL_DB_PASSWORD,
database: process.env.DSQL_DB_NAME,
port: process.env.DSQL_DB_PORT
? Number(process.env.DSQL_DB_PORT)
: undefined,
charset: "utf8mb4",
},
});
const CONNECTION = (0, grab_dsql_connection_1.default)();
try {
return new Promise((resolve, reject) => {
CONNECTION.query(...args)