|
|
@ -2353,21 +2353,24 @@ class BaseModelSqlv2 { |
|
|
|
NcError.notImplemented('Grouping for virtual columns not implemented'); |
|
|
|
NcError.notImplemented('Grouping for virtual columns not implemented'); |
|
|
|
|
|
|
|
|
|
|
|
// extract distinct group column values
|
|
|
|
// extract distinct group column values
|
|
|
|
let groupingValues; |
|
|
|
let groupingValues: Set<any>; |
|
|
|
if (args.options?.length) { |
|
|
|
if (args.options?.length) { |
|
|
|
groupingValues = args.options; |
|
|
|
groupingValues = new Set(args.options); |
|
|
|
} else if (column.uidt === UITypes.SingleSelect) { |
|
|
|
} else if (column.uidt === UITypes.SingleSelect) { |
|
|
|
const colOptions = await column.getColOptions< |
|
|
|
const colOptions = await column.getColOptions< |
|
|
|
SelectOption[] & { options } |
|
|
|
SelectOption[] & { options } |
|
|
|
>(); |
|
|
|
>(); |
|
|
|
groupingValues = colOptions.options.map((opt) => opt.title); |
|
|
|
groupingValues = new Set(colOptions.options.map((opt) => opt.title)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
groupingValues = ( |
|
|
|
groupingValues = new Set( |
|
|
|
|
|
|
|
( |
|
|
|
await this.dbDriver(this.model.table_name) |
|
|
|
await this.dbDriver(this.model.table_name) |
|
|
|
.select(column.column_name) |
|
|
|
.select(column.column_name) |
|
|
|
.distinct() |
|
|
|
.distinct() |
|
|
|
).map((row) => row[column.column_name]); |
|
|
|
).map((row) => row[column.column_name]) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
groupingValues.add(null); |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(this.model.table_name); |
|
|
|
const qb = this.dbDriver(this.model.table_name); |
|
|
|
qb.limit(+rest?.limit || 25); |
|
|
|
qb.limit(+rest?.limit || 25); |
|
|
@ -2451,7 +2454,7 @@ class BaseModelSqlv2 { |
|
|
|
this.isSqlite |
|
|
|
this.isSqlite |
|
|
|
? this.dbDriver.select().from(nullListQb) |
|
|
|
? this.dbDriver.select().from(nullListQb) |
|
|
|
: nullListQb, |
|
|
|
: nullListQb, |
|
|
|
...groupingValues.map((r) => { |
|
|
|
...[...groupingValues].map((r) => { |
|
|
|
const query = qb.clone().where(column.title, r); |
|
|
|
const query = qb.clone().where(column.title, r); |
|
|
|
|
|
|
|
|
|
|
|
return this.isSqlite |
|
|
|
return this.isSqlite |
|
|
@ -2471,13 +2474,22 @@ class BaseModelSqlv2 { |
|
|
|
return d; |
|
|
|
return d; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// todo: handle null values
|
|
|
|
const groupedResult = result.reduce<Map<string | number | null, any[]>>( |
|
|
|
const groupedResult: Record<string, Record<string, unknown>[]> = |
|
|
|
(aggObj, row) => { |
|
|
|
_.groupBy(result, column.title); |
|
|
|
if (!aggObj.has(row[column.title])) { |
|
|
|
|
|
|
|
aggObj.set(row[column.title], []); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
aggObj.get(row[column.title]).push(row); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return aggObj; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
new Map() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const r = groupingValues.map((key) => ({ |
|
|
|
const r = [...groupingValues].map((key) => ({ |
|
|
|
key, |
|
|
|
key, |
|
|
|
value: groupedResult[key] ?? [], |
|
|
|
value: groupedResult.get(key) ?? [], |
|
|
|
})); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
return r; |
|
|
|
return r; |
|
|
|