Updates
This commit is contained in:
+3
-3
@@ -1,5 +1,5 @@
|
||||
import { DSQLErrorObject } from "../../types";
|
||||
import type { ConnectionConfig, Pool } from "mariadb";
|
||||
import mariadb, { ConnectionConfig } from "mariadb";
|
||||
export type ConnDBHandlerQueryObject = {
|
||||
query: string;
|
||||
values?: (string | number | undefined)[];
|
||||
@@ -16,9 +16,9 @@ type Return<ReturnType = any> = ReturnType | ReturnType[] | null | {
|
||||
*/
|
||||
export default function connDbHandler<ReturnType = any>(
|
||||
/**
|
||||
* MariaDB Connection Pool Object
|
||||
* MariaDB Connection
|
||||
*/
|
||||
connPool?: Pool,
|
||||
conn?: mariadb.Connection,
|
||||
/**
|
||||
* String Or `ConnDBHandlerQueryObject` Array
|
||||
*/
|
||||
|
||||
+7
-6
@@ -21,9 +21,9 @@ const debug_log_1 = __importDefault(require("../logging/debug-log"));
|
||||
*/
|
||||
function connDbHandler(
|
||||
/**
|
||||
* MariaDB Connection Pool Object
|
||||
* MariaDB Connection
|
||||
*/
|
||||
connPool,
|
||||
conn,
|
||||
/**
|
||||
* String Or `ConnDBHandlerQueryObject` Array
|
||||
*/
|
||||
@@ -35,13 +35,13 @@ values, debug) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a, _b;
|
||||
try {
|
||||
if (!connPool)
|
||||
if (!conn)
|
||||
throw new Error("No Connection Found!");
|
||||
if (!query)
|
||||
throw new Error("Query String Required!");
|
||||
let queryErrorArray = [];
|
||||
if (typeof query == "string") {
|
||||
const res = yield connPool.query(trimQuery(query), values);
|
||||
const res = yield conn.query(trimQuery(query), values);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: res,
|
||||
@@ -62,7 +62,7 @@ values, debug) {
|
||||
const queryObj = query[i];
|
||||
currentQueryError.sql = queryObj.query;
|
||||
currentQueryError.sqlValues = queryObj.values;
|
||||
const queryObjRes = yield connPool.query(trimQuery(queryObj.query), queryObj.values);
|
||||
const queryObjRes = yield conn.query(trimQuery(queryObj.query), queryObj.values);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: queryObjRes,
|
||||
@@ -79,6 +79,7 @@ values, debug) {
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Connection DB Handler Query Error`, error);
|
||||
console.log("query", query);
|
||||
resArray.push(null);
|
||||
currentQueryError["error"] = error.message;
|
||||
queryErrorArray.push(currentQueryError);
|
||||
@@ -117,7 +118,7 @@ values, debug) {
|
||||
};
|
||||
}
|
||||
finally {
|
||||
connPool === null || connPool === void 0 ? void 0 : connPool.end();
|
||||
yield (conn === null || conn === void 0 ? void 0 : conn.end());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user