|
|
@ -339,6 +339,12 @@ class BaseModelSqlv2 { |
|
|
|
|
|
|
|
|
|
|
|
let data; |
|
|
|
let data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${qb.toQuery()} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
data = await this.execAndParse(qb); |
|
|
|
data = await this.execAndParse(qb); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -499,6 +505,7 @@ class BaseModelSqlv2 { |
|
|
|
args.column_name = args.column_name || ''; |
|
|
|
args.column_name = args.column_name || ''; |
|
|
|
|
|
|
|
|
|
|
|
const cols = await this.model.getColumns(); |
|
|
|
const cols = await this.model.getColumns(); |
|
|
|
|
|
|
|
const groupByColumns: Record<string, Column> = {}; |
|
|
|
|
|
|
|
|
|
|
|
const selectors = []; |
|
|
|
const selectors = []; |
|
|
|
const groupBySelectors = []; |
|
|
|
const groupBySelectors = []; |
|
|
@ -508,11 +515,13 @@ class BaseModelSqlv2 { |
|
|
|
const column = cols.find( |
|
|
|
const column = cols.find( |
|
|
|
(c) => c.column_name === col || c.title === col, |
|
|
|
(c) => c.column_name === col || c.title === col, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
groupByColumns[column.id] = column; |
|
|
|
if (!column) { |
|
|
|
if (!column) { |
|
|
|
throw NcError.notFound('Column not found'); |
|
|
|
throw NcError.notFound('Column not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (column.uidt) { |
|
|
|
switch (column.uidt) { |
|
|
|
|
|
|
|
case UITypes.Links: |
|
|
|
case UITypes.Rollup: |
|
|
|
case UITypes.Rollup: |
|
|
|
selectors.push( |
|
|
|
selectors.push( |
|
|
|
( |
|
|
|
( |
|
|
@ -554,8 +563,6 @@ class BaseModelSqlv2 { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case UITypes.Lookup: |
|
|
|
case UITypes.Lookup: |
|
|
|
{ |
|
|
|
{ |
|
|
|
let selectQb; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
const _selectQb = await generateBTLookupSelectQuery({ |
|
|
|
const _selectQb = await generateBTLookupSelectQuery({ |
|
|
|
baseModelSqlv2: this, |
|
|
|
baseModelSqlv2: this, |
|
|
|
column, |
|
|
|
column, |
|
|
@ -563,25 +570,18 @@ class BaseModelSqlv2 { |
|
|
|
model: this.model, |
|
|
|
model: this.model, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
selectQb = this.dbDriver.raw(`?? as ??`, [ |
|
|
|
const selectQb = this.dbDriver.raw(`?? as ??`, [ |
|
|
|
this.dbDriver.raw(_selectQb.builder).wrap('(', ')'), |
|
|
|
this.dbDriver.raw(_selectQb.builder).wrap('(', ')'), |
|
|
|
sanitize(column.title), |
|
|
|
sanitize(column.title), |
|
|
|
]); |
|
|
|
]); |
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.log(e); |
|
|
|
|
|
|
|
// return dummy select
|
|
|
|
|
|
|
|
selectQb = this.dbDriver.raw(`'ERR' as ??`, [ |
|
|
|
|
|
|
|
sanitize(column.title), |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
selectors.push(selectQb); |
|
|
|
selectors.push(selectQb); |
|
|
|
groupBySelectors.push(column.title); |
|
|
|
groupBySelectors.push(sanitize(column.title)); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
selectors.push(column.column_name); |
|
|
|
selectors.push(column.column_name); |
|
|
|
groupBySelectors.push(sanitize(column.title)); |
|
|
|
groupBySelectors.push(sanitize(column.column_name)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}), |
|
|
|
}), |
|
|
@ -634,6 +634,17 @@ class BaseModelSqlv2 { |
|
|
|
? args.sortArr |
|
|
|
? args.sortArr |
|
|
|
: await Sort.list({ viewId: this.viewId }); |
|
|
|
: await Sort.list({ viewId: this.viewId }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sorts = sorts.filter((sort) => { |
|
|
|
|
|
|
|
if (!groupByColumns[sort.fk_column_id]) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qb.orderBy( |
|
|
|
|
|
|
|
groupByColumns[sort.fk_column_id].column_name || |
|
|
|
|
|
|
|
groupByColumns[sort.fk_column_id].title, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (sorts) await sortV2(this, sorts, qb); |
|
|
|
if (sorts) await sortV2(this, sorts, qb); |
|
|
|
applyPaginate(qb, rest); |
|
|
|
applyPaginate(qb, rest); |
|
|
|
return await qb; |
|
|
|
return await qb; |
|
|
@ -668,6 +679,7 @@ class BaseModelSqlv2 { |
|
|
|
|
|
|
|
|
|
|
|
switch (column.uidt) { |
|
|
|
switch (column.uidt) { |
|
|
|
case UITypes.Rollup: |
|
|
|
case UITypes.Rollup: |
|
|
|
|
|
|
|
case UITypes.Links: |
|
|
|
selectors.push( |
|
|
|
selectors.push( |
|
|
|
( |
|
|
|
( |
|
|
|
await genRollupSelectv2({ |
|
|
|
await genRollupSelectv2({ |
|
|
@ -725,7 +737,7 @@ class BaseModelSqlv2 { |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
selectors.push(column.column_name); |
|
|
|
selectors.push(column.column_name); |
|
|
|
groupBySelectors.push(sanitize(column.title)); |
|
|
|
groupBySelectors.push(sanitize(column.column_name)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}), |
|
|
|
}), |
|
|
@ -4894,7 +4906,7 @@ async function generateBTLookupSelectQuery({ |
|
|
|
{ |
|
|
|
{ |
|
|
|
let aliasCount = 0, |
|
|
|
let aliasCount = 0, |
|
|
|
selectQb; |
|
|
|
selectQb; |
|
|
|
const alias = `__nc_lookup${aliasCount++}`; |
|
|
|
const alias = `__nc_lk_${aliasCount++}`; |
|
|
|
const lookup = await column.getColOptions<LookupColumn>(); |
|
|
|
const lookup = await column.getColOptions<LookupColumn>(); |
|
|
|
{ |
|
|
|
{ |
|
|
|
const relationCol = await lookup.getRelationColumn(); |
|
|
|
const relationCol = await lookup.getRelationColumn(); |
|
|
@ -4925,7 +4937,7 @@ async function generateBTLookupSelectQuery({ |
|
|
|
let lookupColumn = await lookup.getLookupColumn(); |
|
|
|
let lookupColumn = await lookup.getLookupColumn(); |
|
|
|
let prevAlias = alias; |
|
|
|
let prevAlias = alias; |
|
|
|
while (lookupColumn.uidt === UITypes.Lookup) { |
|
|
|
while (lookupColumn.uidt === UITypes.Lookup) { |
|
|
|
const nestedAlias = `__nc_sort${aliasCount++}`; |
|
|
|
const nestedAlias = `__nc_lk_nested_${aliasCount++}`; |
|
|
|
const nestedLookup = await lookupColumn.getColOptions<LookupColumn>(); |
|
|
|
const nestedLookup = await lookupColumn.getColOptions<LookupColumn>(); |
|
|
|
const relationCol = await nestedLookup.getRelationColumn(); |
|
|
|
const relationCol = await nestedLookup.getRelationColumn(); |
|
|
|
const relation = |
|
|
|
const relation = |
|
|
|