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,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv").config({ path: "./../.env" });
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const grab_dsql_connection_1 = __importDefault(require("../utils/grab-dsql-connection"));
/**
* # Main DB Handler Function
* @async
@@ -26,18 +26,7 @@ const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
* @returns {Promise<object|null>}
*/
(() => __awaiter(void 0, 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 {
const result = yield CONNECTION.query("SELECT id,first_name,last_name FROM users LIMIT 3");
console.log("Connection Query Success =>", result);
+4 -14
View File
@@ -13,18 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv").config({ path: "./.env" });
const grabDbSSL_1 = __importDefault(require("../utils/backend/grabDbSSL"));
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const connection = (0, serverless_mysql_1.default)({
config: {
host: process.env.DSQL_DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
// database: process.env.DSQL_DB_NAME,
charset: "utf8mb4",
ssl: (0, grabDbSSL_1.default)(),
},
});
const grab_dsql_connection_1 = __importDefault(require("../utils/grab-dsql-connection"));
/**
* # Main DB Handler Function
* @async
@@ -37,13 +26,14 @@ const connection = (0, serverless_mysql_1.default)({
* @returns {Promise<object|null>}
*/
(() => __awaiter(void 0, void 0, void 0, function* () {
const CONNECTION = (0, grab_dsql_connection_1.default)({ noDb: true });
/**
* Switch Database
*
* @description If a database is provided, switch to it
*/
try {
const result = yield connection.query("SHOW DATABASES");
const result = yield CONNECTION.query("SHOW DATABASES");
const parsedResults = JSON.parse(JSON.stringify(result));
console.log("parsedResults =>", parsedResults);
}
@@ -51,7 +41,7 @@ const connection = (0, serverless_mysql_1.default)({
console.log("Connection query ERROR =>", error.message);
}
finally {
connection.end();
CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end();
process.exit();
}
}))();
+2 -13
View File
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv").config({ path: "./../.env" });
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const grab_dsql_connection_1 = __importDefault(require("../utils/grab-dsql-connection"));
/**
* # Main DB Handler Function
* @async
@@ -27,18 +27,7 @@ const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
*/
(() => __awaiter(void 0, void 0, void 0, function* () {
var _a;
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 {
const result = yield CONNECTION.query("SELECT user,host,ssl_type FROM mysql.user");
const parsedResults = JSON.parse(JSON.stringify(result));
+2 -13
View File
@@ -15,25 +15,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = dbHandler;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
const grab_dsql_connection_1 = __importDefault(require("../../utils/grab-dsql-connection"));
/**
* # Main DB Handler Function
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
*/
function dbHandler(_a) {
return __awaiter(this, arguments, void 0, function* ({ query, values, }) {
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)();
let results;
try {
if (query && values) {