diff --git a/package-shared/functions/dsql/sql/sql-generator.js b/package-shared/functions/dsql/sql/sql-generator.js index c4df218..1b6577f 100644 --- a/package-shared/functions/dsql/sql/sql-generator.js +++ b/package-shared/functions/dsql/sql/sql-generator.js @@ -131,14 +131,16 @@ function sqlGenerator({ tableName, genObject }) { if (joinObj.selectFields) { return joinObj.selectFields - .map((slFld) => { - if (typeof slFld == "string") { - return `${joinTableName}.${slFld}`; - } else if (typeof slFld == "object") { - let aliasSlctFld = `${joinTableName}.${slFld.field}`; - if (slFld.alias) - aliasSlctFld += ` as ${slFld.alias}`; - return aliasSlctFld; + .map((selectField) => { + if (typeof selectField == "string") { + return `${joinTableName}.${selectField}`; + } else if (typeof selectField == "object") { + let aliasSelectField = selectField.count + ? `COUNT(${joinTableName}.${selectField.field})` + : `${joinTableName}.${selectField.field}`; + if (selectField.alias) + aliasSelectField += ` AS ${selectField.alias}`; + return aliasSelectField; } }) .join(","); diff --git a/package-shared/types/index.d.ts b/package-shared/types/index.d.ts index 2125294..cb2431c 100644 --- a/package-shared/types/index.d.ts +++ b/package-shared/types/index.d.ts @@ -955,6 +955,7 @@ export type ServerQueryParamsJoin