This commit is contained in:
Benjamin Toby
2025-08-05 13:56:51 +01:00
parent ab13c68c8e
commit 43a741f9ac
26 changed files with 109 additions and 115 deletions
+11 -8
View File
@@ -1,8 +1,9 @@
import fs from "fs";
import path from "path";
import grabDSQLConnection from "../../utils/grab-dsql-connection";
import { DSQL_TableSchemaType } from "../../types";
import { DSQL_TableSchemaType, PostInsertReturn } from "../../types";
import { Connection, ConnectionConfig } from "mariadb";
import { ServerlessMysql } from "serverless-mysql";
type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
query: string;
@@ -18,7 +19,7 @@ type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
*/
export default async function dbHandler<
T extends { [k: string]: any } = { [k: string]: any }
T extends { [k: string]: any } = PostInsertReturn
>({
query,
values,
@@ -26,21 +27,23 @@ export default async function dbHandler<
database,
config,
}: Param<T>): Promise<T[] | T | null> {
let CONNECTION: Connection | undefined;
let CONNECTION: ServerlessMysql | undefined;
let results: T[] | T | null;
try {
CONNECTION = await grabDSQLConnection({ database, config });
if (query && values) {
const queryResults = await CONNECTION.query(query, values);
results = queryResults[0];
const queryResults = (await CONNECTION.query(query, values)) as
| T
| T[];
results = queryResults;
} else {
const queryResults = await CONNECTION.query(query);
results = queryResults[0];
const queryResults = (await CONNECTION.query(query)) as T | T[];
results = queryResults;
}
} catch (error: any) {
console.log("Connection Info =>", CONNECTION?.info);
console.log("Connection Info =>", CONNECTION?.getConfig());
if (
error.message &&