Browse Source

feat: formula - mysql - value function support

pull/7019/head
Pranav C 1 year ago
parent
commit
cd3f25d0b1
  1. 2
      packages/nocodb/src/db/functionMappings/commonFns.ts
  2. 14
      packages/nocodb/src/db/functionMappings/mysql.ts

2
packages/nocodb/src/db/functionMappings/commonFns.ts

@ -186,7 +186,7 @@ export default {
}; };
}, },
// todo: verify the behaviour of this function // todo: verify the behaviour of this function
COUNTALL: async ({ knex, pt,}: MapFnArgs) => { COUNTALL: async ({ knex, pt }: MapFnArgs) => {
return { return {
builder: knex.raw('? ${colAlias}', [pt.arguments.length]), builder: knex.raw('? ${colAlias}', [pt.arguments.length]),
}; };

14
packages/nocodb/src/db/functionMappings/mysql.ts

@ -146,6 +146,20 @@ const mysql2 = {
builder: knex.raw(`${args.join(' XOR ')} ${colAlias}`), builder: knex.raw(`${args.join(' XOR ')} ${colAlias}`),
}; };
}, },
VALUE: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
const value = (await fn(pt.arguments[0])).builder.toString();
return {
builder: knex.raw(
`ROUND(CASE
WHEN ${value} IS NULL OR REGEXP_REPLACE(${value}, '[^0-9.]+', '') IN ('.', '') OR LENGTH(REGEXP_REPLACE(${value}, '[^.]+', '')) > 1 THEN NULL
WHEN LENGTH(REGEXP_REPLACE(${value}, '[^%]', '')) > 0 THEN POW(-1, LENGTH(REGEXP_REPLACE(${value}, '[^-]',''))) * (REGEXP_REPLACE(${value}, '[^0-9.]+', '')) / 100
ELSE POW(-1, LENGTH(REGEXP_REPLACE(${value}, '[^-]', ''))) * (REGEXP_REPLACE(${value}, '[^0-9.]+', ''))
END) ${colAlias}`,
),
};
},
}; };
export default mysql2; export default mysql2;

Loading…
Cancel
Save