This commit is contained in:
Benjamin Toby
2025-01-15 22:30:01 +01:00
parent 342056060b
commit a2feec6f5b
4 changed files with 20 additions and 9 deletions
+2 -2
View File
@@ -13,11 +13,11 @@ export default function connDbHandler<ReturnType = any>(
/**
* ServerlessMySQL Connection Object
*/
conn: ServerlessMysql,
conn?: ServerlessMysql,
/**
* String Or `QueryObject` Array
*/
query: QueryObject["query"] | QueryObject[],
query?: QueryObject["query"] | QueryObject[],
/**
* Array of Values to Sanitize and Inject
*/
+7 -1
View File
@@ -30,6 +30,10 @@ query,
values) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!conn)
throw new Error("No Connection Found!");
if (!query)
throw new Error("Query String Required!");
if (typeof query == "string") {
const res = yield conn.query(trimQuery(query), values);
return JSON.parse(JSON.stringify(res));
@@ -43,6 +47,7 @@ values) {
resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
}
catch (error) {
console.log(`connDbHandler Query Error: ${error.message}`);
resArray.push(null);
}
}
@@ -53,10 +58,11 @@ values) {
}
}
catch (error) {
console.log(`connDbHandler Error: ${error.message}`);
return null;
}
finally {
conn.end();
conn === null || conn === void 0 ? void 0 : conn.end();
}
});
}