Browse Source

feat(api): add option to pass aggregate field name

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3962/head
Pranav C 2 years ago
parent
commit
457b0b1128
  1. 1
      packages/nocodb/src/lib/meta/NcMetaIO.ts
  2. 3
      packages/nocodb/src/lib/meta/NcMetaIOImpl.ts

1
packages/nocodb/src/lib/meta/NcMetaIO.ts

@ -169,6 +169,7 @@ export default abstract class NcMetaIO {
args?: { args?: {
condition?: { [key: string]: any }; condition?: { [key: string]: any };
xcCondition?: XcCondition; xcCondition?: XcCondition;
aggField?: string;
} }
): Promise<number>; ): Promise<number>;

3
packages/nocodb/src/lib/meta/NcMetaIOImpl.ts

@ -374,6 +374,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
args?: { args?: {
condition?: { [p: string]: any }; condition?: { [p: string]: any };
xcCondition?; xcCondition?;
aggField?: string;
} }
): Promise<number> { ): Promise<number> {
const query = this.knexConnection(target); const query = this.knexConnection(target);
@ -393,7 +394,7 @@ export default class NcMetaIOImpl extends NcMetaIO {
(query as any).condition(args.xcCondition); (query as any).condition(args.xcCondition);
} }
query.count('id', { as: 'count' }).first(); query.count(args?.aggField || 'id', { as: 'count' }).first();
return +(await query)?.['count'] || 0; return +(await query)?.['count'] || 0;
} }

Loading…
Cancel
Save