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. 57
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

57
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,22 +1472,20 @@ 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, // todo: verify syntax of as ? / ??
this.dbDriver, qb.select(
this.model this.dbDriver.raw(`?? as ??`, [
// this.aliasToColumn selectQb.builder,
); sanitize(column.title),
// todo: verify syntax of as ? / ?? ])
qb.select( );
this.dbDriver.raw(`?? as ??`, [ } catch {
selectQb.builder, continue;
sanitize(column.title), }
])
);
} }
break; break;
case 'Rollup': case 'Rollup':

Loading…
Cancel
Save