Browse Source

feat: formula - add counta function

pull/7019/head
Pranav C 1 year ago
parent
commit
79ae6416b1
  1. 20
      packages/nc-gui/utils/formulaUtils.ts
  2. 28
      packages/nocodb/src/db/functionMappings/pg.ts

20
packages/nc-gui/utils/formulaUtils.ts

@ -529,6 +529,26 @@ const formulas: Record<string, any> = {
syntax: 'RECORD_ID()',
examples: ['RECORD_ID()'],
},
COUNTA: {
validation: {
args: {
min:1,
},
},
description: '',
syntax: 'COUNTA()',
examples: ['COUNTA()'],
},
COUNT: {
validation: {
args: {
rqd: 0,
},
},
description: '',
syntax: 'COUNT()',
examples: ['COUNT()'],
},
}
const formulaList = Object.keys(formulas)

28
packages/nocodb/src/db/functionMappings/pg.ts

@ -225,6 +225,34 @@ const pg = {
builder: knex.raw(`${args.join(' # ')} ${colAlias}`),
};
},
COUNT: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex.raw(
`${(
await Promise.all(
pt.arguments.map(async (arg) => {
const { builder } = await fn(arg);
return `CASE WHEN ${builder} IS NOT NULL AND ${builder}::text != '' THEN 1 ELSE 0 END`;
}),
)
).join(' + ')} ${colAlias}`,
),
};
},
COUNTA: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex.raw(
`${(
await Promise.all(
pt.arguments.map(async (arg) => {
const { builder } = await fn(arg);
return `CASE WHEN ${builder} IS NOT NULL AND ${builder}::text != '' THEN 1 ELSE 0 END`;
}),
)
).join(' + ')} ${colAlias}`,
),
};
},
};
export default pg;

Loading…
Cancel
Save