From 9ae951797a680e455171cd76a669a752a0def839 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 21 Aug 2021 16:15:12 +0530 Subject: [PATCH] feat: Support Logical function `AND` and `OR` Signed-off-by: Pranav C --- packages/nc-gui/helpers/formulaList.js | 10 ++++++++++ .../content/en/setup-and-usages/abstract-types.md | 2 +- .../noco-docs/content/en/setup-and-usages/audit.md | 2 +- .../dataMapper/lib/sql/functionMappings/commonFns.ts | 12 +++++++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/nc-gui/helpers/formulaList.js b/packages/nc-gui/helpers/formulaList.js index 9c053df3bd..45553c2070 100644 --- a/packages/nc-gui/helpers/formulaList.js +++ b/packages/nc-gui/helpers/formulaList.js @@ -9,6 +9,16 @@ const validations = { args: { min: 1 } } }, + AND: { + validation: { + args: { min: 1 } + } + }, + OR: { + validation: { + args: { min: 1 } + } + }, CONCAT: { validation: { args: { min: 1 } } }, diff --git a/packages/noco-docs/content/en/setup-and-usages/abstract-types.md b/packages/noco-docs/content/en/setup-and-usages/abstract-types.md index 9be436bc19..a9e2238143 100644 --- a/packages/noco-docs/content/en/setup-and-usages/abstract-types.md +++ b/packages/noco-docs/content/en/setup-and-usages/abstract-types.md @@ -328,7 +328,7 @@ menuTitle: 'Abstract Types' ### Formula - +For more about formula visit [here](./formula) ### Count diff --git a/packages/noco-docs/content/en/setup-and-usages/audit.md b/packages/noco-docs/content/en/setup-and-usages/audit.md index 9394c4d5dc..0501ca1b9a 100644 --- a/packages/noco-docs/content/en/setup-and-usages/audit.md +++ b/packages/noco-docs/content/en/setup-and-usages/audit.md @@ -1,7 +1,7 @@ --- title: 'Audit' description: 'Audit log' -position: 13 +position: 13.5 category: 'Setup and Usages' menuTitle: 'Audit' --- diff --git a/packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/commonFns.ts b/packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/commonFns.ts index 50e64c3e43..24a78387e3 100644 --- a/packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/commonFns.ts +++ b/packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/commonFns.ts @@ -3,7 +3,7 @@ import {MapFnArgs} from "../mapFunctionName"; export default { // todo: handle default case SWITCH: (args: MapFnArgs) => { - const count = Math.floor((args.pt.arguments.length-1) / 2) + const count = Math.floor((args.pt.arguments.length - 1) / 2) let query = ''; const switchVal = args.fn(args.pt.arguments[0]).toQuery(); @@ -23,6 +23,12 @@ export default { } return args.knex.raw(`CASE ${query}\n END${args.colAlias}`) }, - TRUE:(_args) => 1, - FALSE:(_args) => 0 + TRUE: (_args) => 1, + FALSE: (_args) => 0, + AND: (args: MapFnArgs) => { + return args.knex.raw(`${args.knex.raw(`${args.pt.arguments.map(ar => args.fn(ar).toQuery()).join(' AND ')}`).wrap('(', ')').toQuery()}${args.colAlias}`) + }, + OR: (args: MapFnArgs) => { + return args.knex.raw(`${args.knex.raw(`${args.pt.arguments.map(ar => args.fn(ar).toQuery()).join(' OR ')}`).wrap('(', ')').toQuery()}${args.colAlias}`) + }, }