Updates
This commit is contained in:
Vendored
+19
-3
@@ -8,8 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("dotenv").config({ path: "./../.env" });
|
||||
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
|
||||
/**
|
||||
* # Main DB Handler Function
|
||||
* @async
|
||||
@@ -22,16 +26,28 @@ require("dotenv").config({ path: "./../.env" });
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const connection = global.DSQL_DB_CONN;
|
||||
const CONNECTION = global.DSQL_DB_CONN ||
|
||||
(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",
|
||||
},
|
||||
});
|
||||
try {
|
||||
const result = yield connection.query("SELECT id,first_name,last_name FROM users LIMIT 3");
|
||||
const result = yield CONNECTION.query("SELECT id,first_name,last_name FROM users LIMIT 3");
|
||||
console.log("Connection Query Success =>", result);
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Connection query ERROR =>", error.message);
|
||||
}
|
||||
finally {
|
||||
connection.end();
|
||||
CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end();
|
||||
process.exit();
|
||||
}
|
||||
}))();
|
||||
|
||||
+20
-4
@@ -8,8 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("dotenv").config({ path: "./../.env" });
|
||||
const serverless_mysql_1 = __importDefault(require("serverless-mysql"));
|
||||
/**
|
||||
* # Main DB Handler Function
|
||||
* @async
|
||||
@@ -23,9 +27,21 @@ require("dotenv").config({ path: "./../.env" });
|
||||
*/
|
||||
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a;
|
||||
const connection = global.DSQL_DB_CONN;
|
||||
const CONNECTION = global.DSQL_DB_CONN ||
|
||||
(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",
|
||||
},
|
||||
});
|
||||
try {
|
||||
const result = yield connection.query("SELECT user,host,ssl_type FROM mysql.user");
|
||||
const result = yield CONNECTION.query("SELECT user,host,ssl_type FROM mysql.user");
|
||||
const parsedResults = JSON.parse(JSON.stringify(result));
|
||||
for (let i = 0; i < parsedResults.length; i++) {
|
||||
const user = parsedResults[i];
|
||||
@@ -38,7 +54,7 @@ require("dotenv").config({ path: "./../.env" });
|
||||
if (ssl_type === "ANY") {
|
||||
continue;
|
||||
}
|
||||
const addUserSSL = yield connection.query(`ALTER USER '${User}'@'${Host}'`);
|
||||
const addUserSSL = yield CONNECTION.query(`ALTER USER '${User}'@'${Host}'`);
|
||||
console.log(`addUserSSL => ${User}@${Host}`, addUserSSL);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +62,7 @@ require("dotenv").config({ path: "./../.env" });
|
||||
console.log("Connection query ERROR =>", error.message);
|
||||
}
|
||||
finally {
|
||||
connection.end();
|
||||
CONNECTION.end();
|
||||
process.exit();
|
||||
}
|
||||
}))();
|
||||
|
||||
+18
-5
@@ -15,20 +15,33 @@ 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"));
|
||||
/**
|
||||
* # 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, }) {
|
||||
let connection = global.DSQL_DB_CONN;
|
||||
const CONNECTION = global.DSQL_DB_CONN ||
|
||||
(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",
|
||||
},
|
||||
});
|
||||
let results;
|
||||
try {
|
||||
if (query && values) {
|
||||
results = yield connection.query(query, values);
|
||||
results = yield CONNECTION.query(query, values);
|
||||
}
|
||||
else {
|
||||
results = yield connection.query(query);
|
||||
results = yield CONNECTION.query(query);
|
||||
}
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
@@ -37,12 +50,12 @@ function dbHandler(_a) {
|
||||
}
|
||||
console.log("ERROR in dbHandler =>", error.message);
|
||||
console.log(error);
|
||||
console.log(connection.config());
|
||||
console.log(CONNECTION.config());
|
||||
fs_1.default.appendFileSync(path_1.default.resolve(__dirname, "../.tmp/dbErrorLogs.txt"), JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
|
||||
results = null;
|
||||
}
|
||||
finally {
|
||||
yield (connection === null || connection === void 0 ? void 0 : connection.end());
|
||||
yield (CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end());
|
||||
}
|
||||
if (results) {
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
|
||||
Reference in New Issue
Block a user