This commit is contained in:
2026-02-21 02:34:48 +01:00
parent 0da68e30b8
commit ac489ce443
5 changed files with 100 additions and 30 deletions
+31 -5
View File
@@ -11,7 +11,6 @@ const sql_gen_operator_gen_1 = __importDefault(require("./sql-gen-operator-gen")
* @description Generates an SQL Query for node module `mysql` or `serverless-mysql`
*/
function sqlGenerator({ tableName, genObject, dbFullName, count }) {
var _a;
const finalQuery = (genObject === null || genObject === void 0 ? void 0 : genObject.query) ? genObject.query : undefined;
const queryKeys = finalQuery ? Object.keys(finalQuery) : undefined;
const sqlSearhValues = [];
@@ -300,10 +299,37 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
queryString += `${isSearchStr ? " AND" : " WHERE"} ${fullTextMatchStr}`;
sqlSearhValues.push(fullTextSearchStr);
}
if ((_a = genObject === null || genObject === void 0 ? void 0 : genObject.group) === null || _a === void 0 ? void 0 : _a[0]) {
queryString += ` GROUP BY ${genObject.group
.map((g) => `\`${g.toString()}\``)
.join(",")}`;
if (genObject === null || genObject === void 0 ? void 0 : genObject.group) {
let group_by_txt = ``;
if (typeof genObject.group == "string") {
group_by_txt = genObject.group;
}
else if (Array.isArray(genObject.group)) {
for (let i = 0; i < genObject.group.length; i++) {
const group = genObject.group[i];
if (typeof group == "string") {
group_by_txt += `\`${group.toString()}\``;
}
else if (typeof group == "object" && group.table) {
group_by_txt += `${group.table}.${String(group.field)}`;
}
else if (typeof group == "object") {
group_by_txt += `${String(group.field)}`;
}
if (i < genObject.group.length - 1) {
group_by_txt += ",";
}
}
}
else if (typeof genObject.group == "object") {
if (genObject.group.table) {
group_by_txt = `${genObject.group.table}.${String(genObject.group.field)}`;
}
else {
group_by_txt = `${String(genObject.group.field)}`;
}
}
queryString += ` GROUP BY ${group_by_txt}`;
}
function grabOrderString(order) {
let orderFields = [];