|
|
@ -2,14 +2,15 @@ import { RelationTypes, UITypes } from 'nocodb-sdk'; |
|
|
|
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 { |
|
|
|
import type { |
|
|
|
|
|
|
|
BarcodeColumn, |
|
|
|
Column, |
|
|
|
Column, |
|
|
|
FormulaColumn, |
|
|
|
FormulaColumn, |
|
|
|
|
|
|
|
LinksColumn, |
|
|
|
LinkToAnotherRecordColumn, |
|
|
|
LinkToAnotherRecordColumn, |
|
|
|
Model, |
|
|
|
QrCodeColumn, |
|
|
|
RollupColumn, |
|
|
|
RollupColumn, |
|
|
|
} from '~/models'; |
|
|
|
} from '~/models'; |
|
|
|
import type { LinksColumn } from '~/models'; |
|
|
|
import { Model } from '~/models'; |
|
|
|
import type { BarcodeColumn, QrCodeColumn } from '~/models'; |
|
|
|
|
|
|
|
import formulaQueryBuilderv2 from '~/db/formulav2/formulaQueryBuilderv2'; |
|
|
|
import formulaQueryBuilderv2 from '~/db/formulav2/formulaQueryBuilderv2'; |
|
|
|
import genRollupSelectv2 from '~/db/genRollupSelectv2'; |
|
|
|
import genRollupSelectv2 from '~/db/genRollupSelectv2'; |
|
|
|
import { getAliasGenerator } from '~/utils'; |
|
|
|
import { getAliasGenerator } from '~/utils'; |
|
|
@ -257,52 +258,73 @@ export default async function generateLookupSelectQuery({ |
|
|
|
prevAlias = nestedAlias; |
|
|
|
prevAlias = nestedAlias; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (lookupColumn.uidt) { |
|
|
|
{ |
|
|
|
case UITypes.Attachment: |
|
|
|
// get basemodel and model of lookup column
|
|
|
|
NcError.badRequest('Group by using attachment column is not supported'); |
|
|
|
const model = await lookupColumn.getModel(); |
|
|
|
break; |
|
|
|
const baseModelSqlv2 = await Model.getBaseModelSQL({ |
|
|
|
case UITypes.Links: |
|
|
|
model, |
|
|
|
case UITypes.Rollup: |
|
|
|
dbDriver: knex, |
|
|
|
{ |
|
|
|
}); |
|
|
|
const builder = ( |
|
|
|
|
|
|
|
await genRollupSelectv2({ |
|
|
|
switch (lookupColumn.uidt) { |
|
|
|
baseModelSqlv2, |
|
|
|
case UITypes.Attachment: |
|
|
|
knex, |
|
|
|
NcError.badRequest( |
|
|
|
columnOptions: |
|
|
|
'Group by using attachment column is not supported', |
|
|
|
(await lookupColumn.getColOptions()) as RollupColumn, |
|
|
|
|
|
|
|
alias: prevAlias, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
).builder; |
|
|
|
|
|
|
|
selectQb.select(builder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case UITypes.Formula: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const builder = ( |
|
|
|
|
|
|
|
await formulaQueryBuilderv2( |
|
|
|
|
|
|
|
baseModelSqlv2, |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
await column.getColOptions<FormulaColumn>() |
|
|
|
|
|
|
|
).formula, |
|
|
|
|
|
|
|
null, |
|
|
|
|
|
|
|
model, |
|
|
|
|
|
|
|
column, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
).builder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectQb.select(builder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
selectQb.select( |
|
|
|
|
|
|
|
`${prevAlias}.${lookupColumn.column_name} as ${lookupColumn.title}`, |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case UITypes.Links: |
|
|
|
break; |
|
|
|
case UITypes.Rollup: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const builder = ( |
|
|
|
|
|
|
|
await genRollupSelectv2({ |
|
|
|
|
|
|
|
baseModelSqlv2, |
|
|
|
|
|
|
|
knex, |
|
|
|
|
|
|
|
columnOptions: |
|
|
|
|
|
|
|
(await lookupColumn.getColOptions()) as RollupColumn, |
|
|
|
|
|
|
|
alias: prevAlias, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
).builder; |
|
|
|
|
|
|
|
selectQb.select(builder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case UITypes.Formula: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const builder = ( |
|
|
|
|
|
|
|
await formulaQueryBuilderv2( |
|
|
|
|
|
|
|
baseModelSqlv2, |
|
|
|
|
|
|
|
( |
|
|
|
|
|
|
|
await lookupColumn.getColOptions<FormulaColumn>() |
|
|
|
|
|
|
|
).formula, |
|
|
|
|
|
|
|
lookupColumn.title, |
|
|
|
|
|
|
|
model, |
|
|
|
|
|
|
|
lookupColumn, |
|
|
|
|
|
|
|
await model.getAliasColMapping(), |
|
|
|
|
|
|
|
prevAlias, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
).builder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectQb.select(builder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case UITypes.DateTime: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
await baseModelSqlv2.selectObject({ |
|
|
|
|
|
|
|
qb: selectQb, |
|
|
|
|
|
|
|
columns: [lookupColumn], |
|
|
|
|
|
|
|
alias: prevAlias, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
selectQb.select( |
|
|
|
|
|
|
|
`${prevAlias}.${lookupColumn.column_name} as ${lookupColumn.title}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// if all relation are belongs to then we don't need to do the aggregation
|
|
|
|
// if all relation are belongs to then we don't need to do the aggregation
|
|
|
|
if (isBtLookup) { |
|
|
|
if (isBtLookup) { |
|
|
|
return { |
|
|
|
return { |
|
|
|