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
*/
conn: ServerlessMysql,
conn?: ServerlessMysql,
/**
* String Or `QueryObject` Array
*/
query: QueryObject["query"] | QueryObject[],
query?: QueryObject["query"] | QueryObject[],
/**
* Array of Values to Sanitize and Inject
*/

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();
}
});
}

View File

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

View File

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