This commit is contained in:
Benjamin Toby 2025-12-03 21:31:18 +01:00
parent 9ab5543c5c
commit 57f06a631f
5 changed files with 18 additions and 5 deletions

View File

@ -142,12 +142,13 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
let countSqls = [];
for (let i = 0; i < genObject.countSubQueries.length; i++) {
const countSubQuery = genObject.countSubQueries[i];
const tableAlias = countSubQuery.table_alias;
let subQStr = `(SELECT COUNT(*)`;
subQStr += ` FROM ${countSubQuery.table}`;
subQStr += ` FROM ${countSubQuery.table}${tableAlias ? ` ${tableAlias}` : ""}`;
subQStr += ` WHERE (`;
for (let j = 0; j < countSubQuery.srcTrgMap.length; j++) {
const csqSrc = countSubQuery.srcTrgMap[j];
subQStr += ` ${countSubQuery.table}.${csqSrc.src}`;
subQStr += ` ${tableAlias || countSubQuery.table}.${csqSrc.src}`;
if (typeof csqSrc.trg == "string") {
subQStr += ` = ?`;
sqlSearhValues.push(csqSrc.trg);

View File

@ -846,6 +846,8 @@ export type ServerQueryParamFullTextSearch<T extends {
};
export type ServerQueryParamsCount = {
table: string;
/** Alias for the Table From which the count is fetched */
table_alias?: string;
srcTrgMap: {
src: string;
trg: string | ServerQueryParamsCountSrcTrgMap;

View File

@ -205,13 +205,21 @@ export default function sqlGenerator<
for (let i = 0; i < genObject.countSubQueries.length; i++) {
const countSubQuery = genObject.countSubQueries[i];
const tableAlias = countSubQuery.table_alias;
let subQStr = `(SELECT COUNT(*)`;
subQStr += ` FROM ${countSubQuery.table}`;
subQStr += ` FROM ${countSubQuery.table}${
tableAlias ? ` ${tableAlias}` : ""
}`;
subQStr += ` WHERE (`;
for (let j = 0; j < countSubQuery.srcTrgMap.length; j++) {
const csqSrc = countSubQuery.srcTrgMap[j];
subQStr += ` ${countSubQuery.table}.${csqSrc.src}`;
subQStr += ` ${tableAlias || countSubQuery.table}.${
csqSrc.src
}`;
if (typeof csqSrc.trg == "string") {
subQStr += ` = ?`;

View File

@ -1035,6 +1035,8 @@ export type ServerQueryParamFullTextSearch<
export type ServerQueryParamsCount = {
table: string;
/** Alias for the Table From which the count is fetched */
table_alias?: string;
srcTrgMap: {
src: string;
trg: string | ServerQueryParamsCountSrcTrgMap;

View File

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