Updates
This commit is contained in:
@@ -27,7 +27,9 @@ export default async function importMariadbDatabase({
|
||||
const finalMariadbHost = mariadbHost || process.env.DSQL_DB_HOST;
|
||||
const finalMariadbPass = mariadbPass || process.env.DSQL_DB_PASSWORD;
|
||||
|
||||
await connDbHandler(null, `CREATE DATABASE IF NOT EXISTS ${dbFullName}`);
|
||||
await connDbHandler({
|
||||
query: `CREATE DATABASE IF NOT EXISTS ${dbFullName}`,
|
||||
});
|
||||
|
||||
const cmd = `${mysqlPath} -u ${finalMariadbUser} -h ${finalMariadbHost} -p"${finalMariadbPass}" ${dbFullName} < ${targetFilePath}`;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ export default async function <
|
||||
countOnly,
|
||||
dbFullName,
|
||||
tableSchema,
|
||||
dbConfig,
|
||||
}: Omit<
|
||||
DsqlCrudParam<T>,
|
||||
"action" | "data" | "sanitize"
|
||||
@@ -56,7 +57,10 @@ export default async function <
|
||||
];
|
||||
}
|
||||
|
||||
const res = await connDbHandler(undefined, connQueries);
|
||||
const res = await connDbHandler({
|
||||
query: connQueries,
|
||||
dsqlConnOpts: { config: dbConfig },
|
||||
});
|
||||
|
||||
const parsedRes = checkArrayDepth(res, 2)
|
||||
? parseDbResults({ unparsedResults: res[0], tableSchema })
|
||||
|
||||
@@ -28,6 +28,7 @@ export default async function dsqlCrud<
|
||||
debug,
|
||||
tableSchema,
|
||||
deleteKeyValuesOperator,
|
||||
dbConfig,
|
||||
} = params;
|
||||
|
||||
const finalData = (sanitize ? sanitize({ data }) : data) as T;
|
||||
@@ -50,6 +51,7 @@ export default async function dsqlCrud<
|
||||
dbFullName,
|
||||
debug,
|
||||
tableSchema,
|
||||
dbConfig,
|
||||
});
|
||||
return INSERT_RESULT;
|
||||
|
||||
@@ -64,6 +66,7 @@ export default async function dsqlCrud<
|
||||
identifierValue: String(targetValue || targetId),
|
||||
debug,
|
||||
tableSchema,
|
||||
dbConfig,
|
||||
});
|
||||
|
||||
return UPDATE_RESULT;
|
||||
@@ -81,11 +84,11 @@ export default async function dsqlCrud<
|
||||
deleteKeyValuesOperator,
|
||||
});
|
||||
|
||||
const res = (await connDbHandler(
|
||||
undefined,
|
||||
deleteQuery?.query,
|
||||
deleteQuery?.values
|
||||
)) as PostInsertReturn;
|
||||
const res = (await connDbHandler({
|
||||
query: deleteQuery?.query,
|
||||
values: deleteQuery?.values,
|
||||
dsqlConnOpts: { config: dbConfig },
|
||||
})) as PostInsertReturn;
|
||||
|
||||
return {
|
||||
success: Boolean(res.affectedRows),
|
||||
|
||||
@@ -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