This commit is contained in:
Benjamin Toby
2025-06-01 11:39:56 +01:00
parent b28b05956b
commit 9b7c98cff6
18 changed files with 151 additions and 54 deletions
@@ -6,5 +6,6 @@ type Param = {
};
export default function addQueue({ queue, userId, dummy }: Param): Promise<(import("../../../types").PostReturn & {
queryObject?: ReturnType<Awaited<typeof import("../../dsql/sql/sql-generator").default>>;
count?: number;
}) | null | undefined>;
export {};
+2 -1
View File
@@ -7,6 +7,7 @@ type Param<T extends {
genObject?: ServerQueryParam<T>;
tableName: string;
dbFullName?: string;
count?: boolean;
};
type Return = {
string: string;
@@ -20,5 +21,5 @@ export default function sqlGenerator<T extends {
[key: string]: any;
} = {
[key: string]: any;
}>({ tableName, genObject, dbFullName }: Param<T>): Return;
}>({ tableName, genObject, dbFullName, count }: Param<T>): Return;
export {};
+9 -6
View File
@@ -5,7 +5,7 @@ exports.default = sqlGenerator;
* # SQL Query Generator
* @description Generates an SQL Query for node module `mysql` or `serverless-mysql`
*/
function sqlGenerator({ tableName, genObject, dbFullName }) {
function sqlGenerator({ tableName, genObject, dbFullName, count }) {
const finalQuery = (genObject === null || genObject === void 0 ? void 0 : genObject.query) ? genObject.query : undefined;
const queryKeys = finalQuery ? Object.keys(finalQuery) : undefined;
const sqlSearhValues = [];
@@ -109,7 +109,10 @@ function sqlGenerator({ tableName, genObject, dbFullName }) {
let queryString = (() => {
var _a, _b, _c;
let str = "SELECT";
if ((_a = genObject === null || genObject === void 0 ? void 0 : genObject.selectFields) === null || _a === void 0 ? void 0 : _a[0]) {
if (count) {
str += ` COUNT(*)`;
}
else if ((_a = genObject === null || genObject === void 0 ? void 0 : genObject.selectFields) === null || _a === void 0 ? void 0 : _a[0]) {
if (genObject.join) {
str += ` ${(_b = genObject.selectFields) === null || _b === void 0 ? void 0 : _b.map((fld) => `${finalDbName}${tableName}.${fld}`).join(",")}`;
}
@@ -125,7 +128,7 @@ function sqlGenerator({ tableName, genObject, dbFullName }) {
str += " *";
}
}
if (genObject === null || genObject === void 0 ? void 0 : genObject.join) {
if ((genObject === null || genObject === void 0 ? void 0 : genObject.join) && !count) {
const existingJoinTableNames = [tableName];
str +=
"," +
@@ -198,13 +201,13 @@ function sqlGenerator({ tableName, genObject, dbFullName }) {
const stringOperator = (genObject === null || genObject === void 0 ? void 0 : genObject.searchOperator) || "AND";
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
}
if (genObject === null || genObject === void 0 ? void 0 : genObject.order)
if ((genObject === null || genObject === void 0 ? void 0 : genObject.order) && !count)
queryString += ` ORDER BY ${genObject.join
? `${finalDbName}${tableName}.${String(genObject.order.field)}`
: String(genObject.order.field)} ${genObject.order.strategy}`;
if (genObject === null || genObject === void 0 ? void 0 : genObject.limit)
if ((genObject === null || genObject === void 0 ? void 0 : genObject.limit) && !count)
queryString += ` LIMIT ${genObject.limit}`;
if (genObject === null || genObject === void 0 ? void 0 : genObject.offset)
if ((genObject === null || genObject === void 0 ? void 0 : genObject.offset) && !count)
queryString += ` OFFSET ${genObject.offset}`;
return {
string: queryString,