Browse Source

qrcode: extract querybuilder logic for formulas

pr-4468-qr-code-extraction
Daniel Spaude 2 years ago
parent
commit
4e9ffc9ca7
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 41
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

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

@ -1211,6 +1211,19 @@ class BaseModelSqlv2 {
}); });
} }
private async getSelectQueryBuilderForFormula(column: Column<any>) {
const formula = await column.getColOptions<FormulaColumn>();
if (formula.error) throw new Error(`Formula error: ${formula.error}`);
const selectQb = await formulaQueryBuilderv2(
formula.formula,
null,
this.dbDriver,
this.model
);
return selectQb;
}
async getProto() { async getProto() {
if (this._proto) { if (this._proto) {
return this._proto; return this._proto;
@ -1438,19 +1451,15 @@ class BaseModelSqlv2 {
switch (qrValueColumn.uidt) { switch (qrValueColumn.uidt) {
case UITypes.Formula: case UITypes.Formula:
{ try {
const formula = const selectQb = await this.getSelectQueryBuilderForFormula(
await qrValueColumn.getColOptions<FormulaColumn>(); qrValueColumn
if (formula.error) continue;
const selectQb = await formulaQueryBuilderv2(
formula.formula,
null,
this.dbDriver,
this.model
); );
qb.select({ qb.select({
[column.column_name]: selectQb.builder, [column.column_name]: selectQb.builder,
}); });
} catch {
continue;
} }
break; break;
default: { default: {
@ -1463,14 +1472,9 @@ class BaseModelSqlv2 {
} }
case 'Formula': case 'Formula':
{ {
const formula = await column.getColOptions<FormulaColumn>(); try {
if (formula.error) continue; const selectQb = await this.getSelectQueryBuilderForFormula(
const selectQb = await formulaQueryBuilderv2( column
formula.formula,
null,
this.dbDriver,
this.model
// this.aliasToColumn
); );
// todo: verify syntax of as ? / ?? // todo: verify syntax of as ? / ??
qb.select( qb.select(
@ -1479,6 +1483,9 @@ class BaseModelSqlv2 {
sanitize(column.title), sanitize(column.title),
]) ])
); );
} catch {
continue;
}
} }
break; break;
case 'Rollup': case 'Rollup':

Loading…
Cancel
Save