This commit is contained in:
Benjamin Toby 2025-12-03 10:07:34 +01:00
parent 672e011cd8
commit 3346486b6b
3 changed files with 43 additions and 27 deletions

View File

@ -260,14 +260,13 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
} }
return genSqlSrchStr({ queryObj, field, join: genObject === null || genObject === void 0 ? void 0 : genObject.join }); return genSqlSrchStr({ queryObj, field, join: genObject === null || genObject === void 0 ? void 0 : genObject.join });
}); });
if ((sqlSearhString === null || sqlSearhString === void 0 ? void 0 : sqlSearhString[0]) && sqlSearhString.find((str) => str)) { const isSearchStr = (sqlSearhString === null || sqlSearhString === void 0 ? void 0 : sqlSearhString[0]) && sqlSearhString.find((str) => str);
if (isSearchStr) {
const stringOperator = (genObject === null || genObject === void 0 ? void 0 : genObject.searchOperator) || "AND"; const stringOperator = (genObject === null || genObject === void 0 ? void 0 : genObject.searchOperator) || "AND";
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`; queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
} }
else if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) && if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) && fullTextSearchStr && fullTextMatchStr) {
fullTextSearchStr && queryString += `${isSearchStr ? " AND" : " WHERE"} ${fullTextMatchStr}`;
fullTextMatchStr) {
queryString += ` WHERE ${fullTextMatchStr}`;
sqlSearhValues.push(fullTextSearchStr); sqlSearhValues.push(fullTextSearchStr);
} }
if ((_a = genObject === null || genObject === void 0 ? void 0 : genObject.group) === null || _a === void 0 ? void 0 : _a[0]) { if ((_a = genObject === null || genObject === void 0 ? void 0 : genObject.group) === null || _a === void 0 ? void 0 : _a[0]) {
@ -276,12 +275,19 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
.join(",")}`; .join(",")}`;
} }
if ((genObject === null || genObject === void 0 ? void 0 : genObject.order) && !count) { if ((genObject === null || genObject === void 0 ? void 0 : genObject.order) && !count) {
queryString += ` ORDER BY ${(genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) && let orderFields = [];
genObject.fullTextSearch.scoreAlias == genObject.order.field let orderSrt = ` ORDER BY`;
? `${genObject.fullTextSearch.scoreAlias}` if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) && genObject.fullTextSearch.scoreAlias) {
: genObject.join orderFields.push(genObject.fullTextSearch.scoreAlias);
? `${finalDbName}${tableName}.${String(genObject.order.field)}` }
: String(genObject.order.field)} ${genObject.order.strategy}`; else if (genObject.join) {
orderFields.push(`${finalDbName}${tableName}.${String(genObject.order.field)})}`);
}
else {
orderFields.push(genObject.order.field);
}
orderSrt += ` ${orderFields.join(", ")} ${genObject.order.strategy}`;
queryString += ` ${orderSrt}`;
} }
if ((genObject === null || genObject === void 0 ? void 0 : genObject.limit) && !count) if ((genObject === null || genObject === void 0 ? void 0 : genObject.limit) && !count)
queryString += ` LIMIT ${genObject.limit}`; queryString += ` LIMIT ${genObject.limit}`;

View File

@ -348,15 +348,16 @@ export default function sqlGenerator<
return genSqlSrchStr({ queryObj, field, join: genObject?.join }); return genSqlSrchStr({ queryObj, field, join: genObject?.join });
}); });
if (sqlSearhString?.[0] && sqlSearhString.find((str) => str)) { const isSearchStr =
sqlSearhString?.[0] && sqlSearhString.find((str) => str);
if (isSearchStr) {
const stringOperator = genObject?.searchOperator || "AND"; const stringOperator = genObject?.searchOperator || "AND";
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`; queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
} else if ( }
genObject?.fullTextSearch &&
fullTextSearchStr && if (genObject?.fullTextSearch && fullTextSearchStr && fullTextMatchStr) {
fullTextMatchStr queryString += `${isSearchStr ? " AND" : " WHERE"} ${fullTextMatchStr}`;
) {
queryString += ` WHERE ${fullTextMatchStr}`;
sqlSearhValues.push(fullTextSearchStr); sqlSearhValues.push(fullTextSearchStr);
} }
@ -367,14 +368,23 @@ export default function sqlGenerator<
} }
if (genObject?.order && !count) { if (genObject?.order && !count) {
queryString += ` ORDER BY ${ let orderFields = [];
genObject?.fullTextSearch &&
genObject.fullTextSearch.scoreAlias == genObject.order.field let orderSrt = ` ORDER BY`;
? `${genObject.fullTextSearch.scoreAlias}`
: genObject.join if (genObject?.fullTextSearch && genObject.fullTextSearch.scoreAlias) {
? `${finalDbName}${tableName}.${String(genObject.order.field)}` orderFields.push(genObject.fullTextSearch.scoreAlias);
: String(genObject.order.field) } else if (genObject.join) {
} ${genObject.order.strategy}`; orderFields.push(
`${finalDbName}${tableName}.${String(genObject.order.field)})}`
);
} else {
orderFields.push(genObject.order.field);
}
orderSrt += ` ${orderFields.join(", ")} ${genObject.order.strategy}`;
queryString += ` ${orderSrt}`;
} }
if (genObject?.limit && !count) queryString += ` LIMIT ${genObject.limit}`; if (genObject?.limit && !count) queryString += ` LIMIT ${genObject.limit}`;

View File

@ -1,6 +1,6 @@
{ {
"name": "@moduletrace/datasquirel", "name": "@moduletrace/datasquirel",
"version": "5.4.5", "version": "5.4.6",
"description": "Cloud-based SQL data management tool", "description": "Cloud-based SQL data management tool",
"main": "dist/index.js", "main": "dist/index.js",
"bin": { "bin": {