First Commit. Based off bun-sqlite

This commit is contained in:
2026-06-21 06:18:34 +01:00
commit 9c8f6e20aa
155 changed files with 11103 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
import type { Connection, ConnectionConfig } from "mariadb";
import type { BUN_MARIADB_TableSchemaType, DBResponseObject } from "../types";
import grabDBConnection from "./grab-db-connection";
type Param = {
query: string;
values?: string[] | object;
noErrorLogs?: boolean;
database?: string;
tableSchema?: BUN_MARIADB_TableSchemaType;
config?: ConnectionConfig;
};
/**
* # Main DB Handler Function
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
*/
export default async function dbHandler<
T extends { [k: string]: any } = { [k: string]: any },
>({
query,
values,
noErrorLogs,
database,
config,
}: Param): Promise<DBResponseObject> {
let CONNECTION: Connection | undefined;
let results: T | null = null;
try {
CONNECTION = await grabDBConnection({ database, config });
if (query && values) {
const queryResults = await CONNECTION.query(query, values);
results = queryResults[0];
} else {
const queryResults = await CONNECTION.query(query);
results = queryResults[0];
}
} catch (error: any) {
if (
error.message &&
typeof error.message == "string" &&
error.message.match(/Access denied for user.*password/i)
) {
throw new Error("Authentication Failed!");
}
if (!noErrorLogs) {
console.log(error);
}
results = null;
} finally {
await CONNECTION?.end();
}
if (results) {
return {
success: true,
payload: Array.isArray(results) ? results : undefined,
single_res: Array.isArray(results) ? undefined : results,
};
} else {
return {
success: false,
};
}
}