From ba45602ff5455e72225d5f7b0b51559923dfc0f6 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 22 Nov 2023 07:17:57 +0000 Subject: [PATCH] feat: formula - mysql - regex_extract and replace --- .../nocodb/src/db/functionMappings/mysql.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/nocodb/src/db/functionMappings/mysql.ts b/packages/nocodb/src/db/functionMappings/mysql.ts index 1037adff29..36be83317b 100644 --- a/packages/nocodb/src/db/functionMappings/mysql.ts +++ b/packages/nocodb/src/db/functionMappings/mysql.ts @@ -121,6 +121,23 @@ const mysql2 = { builder: knex.raw(`(${source} REGEXP ${pattern}) ${colAlias}`), }; }, + REGEX_EXTRACT: async ({ fn, knex, pt, colAlias }: MapFnArgs) => { + const source = (await fn(pt.arguments[0])).builder; + const pattern = (await fn(pt.arguments[1])).builder; + return { + builder: knex.raw(`REGEXP_SUBSTR(${source}, ${pattern}) ${colAlias}`), + }; + }, + REGEX_REPLACE: async ({ fn, knex, pt, colAlias }: MapFnArgs) => { + const source = (await fn(pt.arguments[0])).builder; + const pattern = (await fn(pt.arguments[1])).builder; + const replacement = (await fn(pt.arguments[2])).builder; + return { + builder: knex.raw( + `REGEXP_REPLACE(${source}, ${pattern}, ${replacement}) ${colAlias}`, + ), + }; + }, }; export default mysql2;