From fb50783b94b3312b2cbf2195d0c3f97a049a3438 Mon Sep 17 00:00:00 2001 From: Pranav C <61551451+pranavxc@users.noreply.github.com> Date: Wed, 5 Oct 2022 14:38:39 +0530 Subject: [PATCH] feat(api): oracledb - formula weekday function support --- .../lib/sql/functionMappings/oracle.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/oracle.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/oracle.ts index d1a3fe0123..94a1023df6 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/oracle.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/oracle.ts @@ -1,5 +1,7 @@ import commonFns from './commonFns'; import { MapFnArgs } from '../mapFunctionName'; +import dayjs from 'dayjs'; +import { getWeekdayByText } from '../helpers/formulaFnHelper'; const pg = { ...commonFns, @@ -63,19 +65,17 @@ const pg = { END${colAlias}` ); }, - // WEEKDAY: ({ fn, knex, pt, colAlias }: MapFnArgs) => { - // // isodow: the day of the week as Monday (1) to Sunday (7) - // // WEEKDAY() returns an index from 0 to 6 for Monday to Sunday - // return knex.raw( - // `(EXTRACT(ISODOW FROM ${ - // pt.arguments[0].type === 'Literal' - // ? `date '${dayjs(fn(pt.arguments[0])).format('YYYY-MM-DD')}'` - // : fn(pt.arguments[0]) - // }) - 1 - ${getWeekdayByText( - // pt?.arguments[1]?.value - // )} % 7 + 7) ::INTEGER % 7 ${colAlias}` - // ); - // }, + WEEKDAY: ({ fn, knex, pt, colAlias }: MapFnArgs) => { + return knex.raw( + `MOD(to_char(${ + pt.arguments[0].type === 'Literal' + ? `date '${dayjs(fn(pt.arguments[0])).format('YYYY-MM-DD')}'` + : fn(pt.arguments[0]) + },'D') - 2 - ${getWeekdayByText( + pt?.arguments[1]?.value + )} + 7, 7) ${colAlias}` + ); + }, }; export default pg;