Updates
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user