Browse Source

refactor(nocodb): reuse the column builder reference across all the formula

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5392/head
Pranav C 2 years ago
parent
commit
15179c9760
  1. 18
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

18
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1283,7 +1283,8 @@ class BaseModelSqlv2 {
private async getSelectQueryBuilderForFormula( private async getSelectQueryBuilderForFormula(
column: Column<any>, column: Column<any>,
tableAlias?: string, tableAlias?: string,
validateFormula = false validateFormula = false,
aliasToColumnBuilder = {}
) { ) {
const formula = await column.getColOptions<FormulaColumn>(); const formula = await column.getColOptions<FormulaColumn>();
if (formula.error) throw new Error(`Formula error: ${formula.error}`); if (formula.error) throw new Error(`Formula error: ${formula.error}`);
@ -1293,7 +1294,7 @@ class BaseModelSqlv2 {
this.dbDriver, this.dbDriver,
this.model, this.model,
column, column,
{}, aliasToColumnBuilder,
tableAlias, tableAlias,
validateFormula validateFormula
); );
@ -1517,7 +1518,7 @@ class BaseModelSqlv2 {
validateFormula, validateFormula,
}: { }: {
fieldsSet?: Set<string>; fieldsSet?: Set<string>;
qb: Knex.QueryBuilder; qb: Knex.QueryBuilder & Knex.QueryInterface;
columns?: Column[]; columns?: Column[];
fields?: string[] | string; fields?: string[] | string;
extractPkAndPv?: boolean; extractPkAndPv?: boolean;
@ -1525,6 +1526,8 @@ class BaseModelSqlv2 {
alias?: string; alias?: string;
validateFormula?: boolean; validateFormula?: boolean;
}): Promise<void> { }): Promise<void> {
// keep a common object for all columns to share across all columns
const aliasToColumnBuilder = {};
let viewOrTableColumns: Column[] | { fk_column_id?: string }[]; let viewOrTableColumns: Column[] | { fk_column_id?: string }[];
const res = {}; const res = {};
@ -1588,7 +1591,8 @@ class BaseModelSqlv2 {
const selectQb = await this.getSelectQueryBuilderForFormula( const selectQb = await this.getSelectQueryBuilderForFormula(
qrValueColumn, qrValueColumn,
alias, alias,
validateFormula validateFormula,
aliasToColumnBuilder
); );
qb.select({ qb.select({
[column.column_name]: selectQb.builder, [column.column_name]: selectQb.builder,
@ -1622,7 +1626,8 @@ class BaseModelSqlv2 {
const selectQb = await this.getSelectQueryBuilderForFormula( const selectQb = await this.getSelectQueryBuilderForFormula(
barcodeValueColumn, barcodeValueColumn,
alias, alias,
validateFormula validateFormula,
aliasToColumnBuilder
); );
qb.select({ qb.select({
[column.column_name]: selectQb.builder, [column.column_name]: selectQb.builder,
@ -1647,7 +1652,8 @@ class BaseModelSqlv2 {
const selectQb = await this.getSelectQueryBuilderForFormula( const selectQb = await this.getSelectQueryBuilderForFormula(
column, column,
alias, alias,
validateFormula validateFormula,
aliasToColumnBuilder
); );
qb.select( qb.select(
this.dbDriver.raw(`?? as ??`, [ this.dbDriver.raw(`?? as ??`, [

Loading…
Cancel
Save