Updates
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import debugLog from "../logging/debug-log";
|
||||
import { DSQLErrorObject } from "../../types";
|
||||
import { DsqlConnectionParam, DSQLErrorObject } from "../../types";
|
||||
import mariadb, { Connection, ConnectionConfig, Pool } from "mariadb";
|
||||
import grabDSQLConnection from "../grab-dsql-connection";
|
||||
|
||||
@@ -14,27 +14,36 @@ type Return<ReturnType = any> =
|
||||
| null
|
||||
| { error?: string; errors?: DSQLErrorObject[]; config?: ConnectionConfig };
|
||||
|
||||
export type ConnectionDbHandlerParams = {
|
||||
/**
|
||||
* MariaDB Connection
|
||||
*/
|
||||
conn?: mariadb.Connection | null;
|
||||
/**
|
||||
* String Or `ConnDBHandlerQueryObject` Array
|
||||
*/
|
||||
query?: ConnDBHandlerQueryObject["query"] | ConnDBHandlerQueryObject[];
|
||||
/**
|
||||
* Array of Values to Sanitize and Inject
|
||||
*/
|
||||
values?: ConnDBHandlerQueryObject["values"];
|
||||
debug?: boolean;
|
||||
dsqlConnOpts?: DsqlConnectionParam;
|
||||
};
|
||||
|
||||
/**
|
||||
* # Run Query From MySQL Connection
|
||||
* @description Run a query from a pre-existing MySQL/Mariadb Connection
|
||||
* setup with `serverless-mysql` npm module
|
||||
*/
|
||||
export default async function connDbHandler<ReturnType = any>(
|
||||
/**
|
||||
* MariaDB Connection
|
||||
*/
|
||||
conn?: mariadb.Connection | null,
|
||||
/**
|
||||
* String Or `ConnDBHandlerQueryObject` Array
|
||||
*/
|
||||
query?: ConnDBHandlerQueryObject["query"] | ConnDBHandlerQueryObject[],
|
||||
/**
|
||||
* Array of Values to Sanitize and Inject
|
||||
*/
|
||||
values?: ConnDBHandlerQueryObject["values"],
|
||||
debug?: boolean
|
||||
): Promise<Return<ReturnType>> {
|
||||
const finalConnection = conn || (await grabDSQLConnection());
|
||||
export default async function connDbHandler<ReturnType = any>({
|
||||
conn,
|
||||
debug,
|
||||
query,
|
||||
values,
|
||||
dsqlConnOpts,
|
||||
}: ConnectionDbHandlerParams): Promise<Return<ReturnType>> {
|
||||
const finalConnection = conn || (await grabDSQLConnection(dsqlConnOpts));
|
||||
|
||||
try {
|
||||
if (!finalConnection) throw new Error("No Connection Found!");
|
||||
|
||||
Reference in New Issue
Block a user