This commit is contained in:
Benjamin Toby
2025-08-05 15:27:07 +01:00
parent 43a741f9ac
commit eb98148533
23 changed files with 84 additions and 116 deletions
+10 -13
View File
@@ -1,11 +1,10 @@
import fs from "fs";
import path from "path";
import grabDSQLConnection from "../../utils/grab-dsql-connection";
import { DSQL_TableSchemaType, PostInsertReturn } from "../../types";
import { DSQL_TableSchemaType } from "../../types";
import { Connection, ConnectionConfig } from "mariadb";
import { ServerlessMysql } from "serverless-mysql";
type Param<T extends { [k: string]: any } = { [k: string]: any }> = {
type Param = {
query: string;
values?: string[] | object;
noErrorLogs?: boolean;
@@ -19,31 +18,29 @@ 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 } = PostInsertReturn
T extends { [k: string]: any } = { [k: string]: any }
>({
query,
values,
noErrorLogs,
database,
config,
}: Param<T>): Promise<T[] | T | null> {
let CONNECTION: ServerlessMysql | undefined;
}: Param): Promise<T[] | T | null> {
let CONNECTION: Connection | undefined;
let results: T[] | T | null;
try {
CONNECTION = await grabDSQLConnection({ database, config });
if (query && values) {
const queryResults = (await CONNECTION.query(query, values)) as
| T
| T[];
results = queryResults;
const queryResults = await CONNECTION.query(query, values);
results = queryResults[0];
} else {
const queryResults = (await CONNECTION.query(query)) as T | T[];
results = queryResults;
const queryResults = await CONNECTION.query(query);
results = queryResults[0];
}
} catch (error: any) {
console.log("Connection Info =>", CONNECTION?.getConfig());
console.log("Connection Info =>", CONNECTION?.info);
if (
error.message &&