Browse Source

feat:populate and save parsed tree if missing

pull/7268/head
Pranav C 11 months ago
parent
commit
24ee8745e1
  1. 11
      packages/nc-gui/utils/formulaUtils.ts
  2. 17
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

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

@ -435,17 +435,6 @@ const formulas: Record<string, FormulaMeta> = {
return argsTypes[1] return argsTypes[1]
}, },
returnType: (argTypes: formulaTypes[]) => {
if (argTypes.slice(1).includes(formulaTypes.STRING)) {
return formulaTypes.STRING
} else if (argTypes.slice(1).includes(formulaTypes.NUMERIC)) {
return formulaTypes.NUMERIC
} else if (argTypes.slice(1).includes(formulaTypes.BOOLEAN)) {
return formulaTypes.BOOLEAN
}
return argTypes[1]
},
}, },
SWITCH: { SWITCH: {
type: formulaTypes.COND_EXP, type: formulaTypes.COND_EXP,

17
packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

@ -7,12 +7,12 @@ import {
} from 'nocodb-sdk'; } from 'nocodb-sdk';
import mapFunctionName from '../mapFunctionName'; import mapFunctionName from '../mapFunctionName';
import genRollupSelectv2 from '../genRollupSelectv2'; import genRollupSelectv2 from '../genRollupSelectv2';
import type Column from '~/models/Column';
import type Model from '~/models/Model'; import type Model from '~/models/Model';
import type RollupColumn from '~/models/RollupColumn'; import type RollupColumn from '~/models/RollupColumn';
import type LinkToAnotherRecordColumn from '~/models/LinkToAnotherRecordColumn'; import type LinkToAnotherRecordColumn from '~/models/LinkToAnotherRecordColumn';
import type LookupColumn from '~/models/LookupColumn'; import type LookupColumn from '~/models/LookupColumn';
import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2'; import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2';
import type Column from '~/models/Column';
import NocoCache from '~/cache/NocoCache'; import NocoCache from '~/cache/NocoCache';
import { CacheGetType, CacheScope } from '~/utils/globals'; import { CacheGetType, CacheScope } from '~/utils/globals';
import { import {
@ -21,7 +21,7 @@ import {
} from '~/helpers/formulaFnHelper'; } from '~/helpers/formulaFnHelper';
import FormulaColumn from '~/models/FormulaColumn'; import FormulaColumn from '~/models/FormulaColumn';
// todo: switch function based on database const logger = new Logger('FormulaQueryBuilderv2');
// @ts-ignore // @ts-ignore
const getAggregateFn: (fnName: string) => (args: { qb; knex?; cn }) => any = ( const getAggregateFn: (fnName: string) => (args: { qb; knex?; cn }) => any = (
@ -64,6 +64,7 @@ async function _formulaQueryBuilder(
aliasToColumn: Record<string, () => Promise<{ builder: any }>> = {}, aliasToColumn: Record<string, () => Promise<{ builder: any }>> = {},
tableAlias?: string, tableAlias?: string,
parsedTree?: any, parsedTree?: any,
column: Column = null,
) { ) {
const knex = baseModelSqlv2.dbDriver; const knex = baseModelSqlv2.dbDriver;
@ -78,6 +79,18 @@ async function _formulaQueryBuilder(
_tree.replaceAll('{{', '{').replaceAll('}}', '}'), _tree.replaceAll('{{', '{').replaceAll('}}', '}'),
columns, columns,
); );
// populate and save parsedTree to column if not exist
if (column) {
FormulaColumn.update(column.id, { parsed_tree: tree }).then(
() => {
// ignore
},
(err) => {
logger.error(err);
},
);
}
} }
const columnIdToUidt = {}; const columnIdToUidt = {};

Loading…
Cancel
Save