Updates
This commit is contained in:
@@ -14,7 +14,6 @@ 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 grabDbSSL_1 = __importDefault(require("../grabDbSSL"));
|
||||
const MASTER = (0, serverless_mysql_1.default)({
|
||||
config: {
|
||||
host: process.env.DSQL_DB_HOST,
|
||||
@@ -25,7 +24,7 @@ const MASTER = (0, serverless_mysql_1.default)({
|
||||
? Number(process.env.DSQL_DB_PORT)
|
||||
: undefined,
|
||||
charset: "utf8mb4",
|
||||
ssl: (0, grabDbSSL_1.default)(),
|
||||
// ssl: grabDbSSL(),
|
||||
},
|
||||
});
|
||||
/**
|
||||
|
||||
@@ -100,4 +100,3 @@ function DSQL_USER_DB_HANDLER({ paradigm, database, queryString, queryValues, })
|
||||
};
|
||||
}
|
||||
}
|
||||
module.exports = DSQL_USER_DB_HANDLER;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { ServerlessMysql } from "serverless-mysql";
|
||||
type QueryObject = {
|
||||
query: string;
|
||||
values?: (string | number | undefined)[];
|
||||
};
|
||||
type Return<ReturnType = any> = ReturnType | null;
|
||||
/**
|
||||
* # Run Query From MySQL Connection
|
||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||
* setup with `serverless-mysql` npm module
|
||||
*/
|
||||
export default function connDbHandler<ReturnType = any>(
|
||||
/**
|
||||
* ServerlessMySQL Connection Object
|
||||
*/
|
||||
conn: ServerlessMysql,
|
||||
/**
|
||||
* String Or `QueryObject` Array
|
||||
*/
|
||||
query: QueryObject["query"] | QueryObject[],
|
||||
/**
|
||||
* Array of Values to Sanitize and Inject
|
||||
*/
|
||||
values?: QueryObject["values"]): Promise<Return<ReturnType>>;
|
||||
export {};
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = connDbHandler;
|
||||
/**
|
||||
* # Run Query From MySQL Connection
|
||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||
* setup with `serverless-mysql` npm module
|
||||
*/
|
||||
function connDbHandler(
|
||||
/**
|
||||
* ServerlessMySQL Connection Object
|
||||
*/
|
||||
conn,
|
||||
/**
|
||||
* String Or `QueryObject` Array
|
||||
*/
|
||||
query,
|
||||
/**
|
||||
* Array of Values to Sanitize and Inject
|
||||
*/
|
||||
values) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
if (typeof query == "string") {
|
||||
const res = yield conn.query(query, values);
|
||||
return JSON.parse(JSON.stringify(res));
|
||||
}
|
||||
else if (typeof query == "object") {
|
||||
const resArray = [];
|
||||
for (let i = 0; i < query.length; i++) {
|
||||
const queryObj = query[i];
|
||||
const queryObjRes = yield conn.query(queryObj.query, queryObj.values);
|
||||
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
|
||||
}
|
||||
return resArray;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
return null;
|
||||
}
|
||||
finally {
|
||||
conn.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
Vendored
+1
-1
@@ -9,7 +9,7 @@ declare function parse(string: string | null | number, reviver?: (this: any, key
|
||||
/**
|
||||
* # EJSON stringify object
|
||||
*/
|
||||
declare function stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string | undefined;
|
||||
declare function stringify(value: any, replacer?: ((this: any, key: string, value: any) => any) | null, space?: string | number): string | undefined;
|
||||
declare const EJSON: {
|
||||
parse: typeof parse;
|
||||
stringify: typeof stringify;
|
||||
|
||||
Vendored
+1
-1
@@ -22,7 +22,7 @@ function parse(string, reviver) {
|
||||
*/
|
||||
function stringify(value, replacer, space) {
|
||||
try {
|
||||
return JSON.stringify(value, replacer, space);
|
||||
return JSON.stringify(value, replacer || undefined, space);
|
||||
}
|
||||
catch (error) {
|
||||
return undefined;
|
||||
|
||||
+6
-1
@@ -1 +1,6 @@
|
||||
export {};
|
||||
import mysql from "mysql";
|
||||
/**
|
||||
* # End MYSQL Connection
|
||||
*/
|
||||
declare function endConnection(connection: mysql.Connection): void;
|
||||
export default endConnection;
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ function endConnection(connection) {
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports = endConnection;
|
||||
exports.default = endConnection;
|
||||
|
||||
Reference in New Issue
Block a user