This commit is contained in:
Benjamin Toby 2024-12-27 09:56:11 +01:00
parent e4590e74d9
commit 0a77a869f7
4 changed files with 13 additions and 9 deletions

View File

@ -131,14 +131,16 @@ function sqlGenerator({ tableName, genObject }) {
if (joinObj.selectFields) { if (joinObj.selectFields) {
return joinObj.selectFields return joinObj.selectFields
.map((slFld) => { .map((selectField) => {
if (typeof slFld == "string") { if (typeof selectField == "string") {
return `${joinTableName}.${slFld}`; return `${joinTableName}.${selectField}`;
} else if (typeof slFld == "object") { } else if (typeof selectField == "object") {
let aliasSlctFld = `${joinTableName}.${slFld.field}`; let aliasSelectField = selectField.count
if (slFld.alias) ? `COUNT(${joinTableName}.${selectField.field})`
aliasSlctFld += ` as ${slFld.alias}`; : `${joinTableName}.${selectField.field}`;
return aliasSlctFld; if (selectField.alias)
aliasSelectField += ` AS ${selectField.alias}`;
return aliasSelectField;
} }
}) })
.join(","); .join(",");

View File

@ -955,6 +955,7 @@ export type ServerQueryParamsJoin<Table extends string = string, Field extends o
selectFields?: (keyof Field | { selectFields?: (keyof Field | {
field: keyof Field; field: keyof Field;
alias?: string; alias?: string;
count?: boolean;
})[]; })[];
}; };
export type ServerQueryParamsJoinMatchObject<Field extends object = { export type ServerQueryParamsJoinMatchObject<Field extends object = {

View File

@ -1141,6 +1141,7 @@ export type ServerQueryParamsJoin<
| { | {
field: keyof Field; field: keyof Field;
alias?: string; alias?: string;
count?: boolean;
} }
)[]; )[];
}; };

View File

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