Browse Source

feat(api): add metaCount method for getting records count

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

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

@ -162,6 +162,16 @@ export default abstract class NcMetaIO {
}
): Promise<any[]>;
public abstract metaCount(
project_id: string,
base_id: string,
target: string,
args?: {
condition?: { [key: string]: any };
xcCondition?: XcCondition;
}
): Promise<number>;
public abstract metaPaginatedList(
project_id: string,
dbAlias: string,

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

@ -366,6 +366,38 @@ export default class NcMetaIOImpl extends NcMetaIO {
return query;
}
public async metaCount(
project_id: string,
dbAlias: string,
target: string,
args?: {
condition?: { [p: string]: any };
xcCondition?;
}
): Promise<number> {
const query = this.knexConnection(target);
if (project_id !== null && project_id !== undefined) {
query.where('project_id', project_id);
}
if (dbAlias !== null && dbAlias !== undefined) {
query.where('base_id', dbAlias);
}
if (args?.condition) {
query.where(args.condition);
}
if (args?.xcCondition) {
(query as any).condition(args.xcCondition);
}
query.count('id', { as: 'count' }).first();
return +(await query)?.['count'] || 0;
}
public async metaUpdate(
project_id: string,
dbAlias: string,

Loading…
Cancel
Save