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

View File

@ -13,11 +13,11 @@ export default function connDbHandler<ReturnType = any>(
/** /**
* ServerlessMySQL Connection Object * ServerlessMySQL Connection Object
*/ */
conn: ServerlessMysql, conn?: ServerlessMysql,
/** /**
* String Or `QueryObject` Array * String Or `QueryObject` Array
*/ */
query: QueryObject["query"] | QueryObject[], query?: QueryObject["query"] | QueryObject[],
/** /**
* Array of Values to Sanitize and Inject * Array of Values to Sanitize and Inject
*/ */

View File

@ -30,6 +30,10 @@ query,
values) { values) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
if (!conn)
throw new Error("No Connection Found!");
if (!query)
throw new Error("Query String Required!");
if (typeof query == "string") { if (typeof query == "string") {
const res = yield conn.query(trimQuery(query), values); const res = yield conn.query(trimQuery(query), values);
return JSON.parse(JSON.stringify(res)); return JSON.parse(JSON.stringify(res));
@ -43,6 +47,7 @@ values) {
resArray.push(JSON.parse(JSON.stringify(queryObjRes))); resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
} }
catch (error) { catch (error) {
console.log(`connDbHandler Query Error: ${error.message}`);
resArray.push(null); resArray.push(null);
} }
} }
@ -53,10 +58,11 @@ values) {
} }
} }
catch (error) { catch (error) {
console.log(`connDbHandler Error: ${error.message}`);
return null; return null;
} }
finally { finally {
conn.end(); conn === null || conn === void 0 ? void 0 : conn.end();
} }
}); });
} }

View File

@ -16,17 +16,20 @@ export default async function connDbHandler<ReturnType = any>(
/** /**
* ServerlessMySQL Connection Object * ServerlessMySQL Connection Object
*/ */
conn: ServerlessMysql, conn?: ServerlessMysql,
/** /**
* String Or `QueryObject` Array * String Or `QueryObject` Array
*/ */
query: QueryObject["query"] | QueryObject[], query?: QueryObject["query"] | QueryObject[],
/** /**
* Array of Values to Sanitize and Inject * Array of Values to Sanitize and Inject
*/ */
values?: QueryObject["values"] values?: QueryObject["values"]
): Promise<Return<ReturnType>> { ): Promise<Return<ReturnType>> {
try { try {
if (!conn) throw new Error("No Connection Found!");
if (!query) throw new Error("Query String Required!");
if (typeof query == "string") { if (typeof query == "string") {
const res = await conn.query(trimQuery(query), values); const res = await conn.query(trimQuery(query), values);
return JSON.parse(JSON.stringify(res)); return JSON.parse(JSON.stringify(res));
@ -41,7 +44,8 @@ export default async function connDbHandler<ReturnType = any>(
queryObj.values queryObj.values
); );
resArray.push(JSON.parse(JSON.stringify(queryObjRes))); resArray.push(JSON.parse(JSON.stringify(queryObjRes)));
} catch (error) { } catch (error: any) {
console.log(`connDbHandler Query Error: ${error.message}`);
resArray.push(null); resArray.push(null);
} }
} }
@ -50,10 +54,11 @@ export default async function connDbHandler<ReturnType = any>(
} else { } else {
return null; return null;
} }
} catch (error) { } catch (error: any) {
console.log(`connDbHandler Error: ${error.message}`);
return null; return null;
} finally { } finally {
conn.end(); conn?.end();
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "3.6.6", "version": "3.6.7",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {