mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-04 21:28:34 +08:00
feat: allow to set distinct for query measures (#5091)
This commit is contained in:
parent
77b60ed16c
commit
ba95bfafe2
@ -289,6 +289,12 @@ export const querySchema: ISchema = {
|
||||
},
|
||||
},
|
||||
},
|
||||
distinct: {
|
||||
type: 'boolean',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Checkbox',
|
||||
'x-content': '{{t("Distinct")}}',
|
||||
},
|
||||
},
|
||||
{
|
||||
required: true,
|
||||
|
@ -94,5 +94,6 @@
|
||||
"Aspect ratio": "Aspect ratio",
|
||||
"Fixed height": "Fixed height",
|
||||
"Show background": "Show background",
|
||||
"Show padding": "Show padding"
|
||||
"Show padding": "Show padding",
|
||||
"Distinct": "Distinct"
|
||||
}
|
||||
|
@ -95,5 +95,6 @@
|
||||
"Aspect ratio": "宽高比",
|
||||
"Fixed height": "固定高度",
|
||||
"Show background": "显示背景",
|
||||
"Show padding": "显示内边距"
|
||||
"Show padding": "显示内边距",
|
||||
"Distinct": "去重"
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ type MeasureProps = {
|
||||
type?: string;
|
||||
aggregation?: string;
|
||||
alias?: string;
|
||||
distinct?: boolean;
|
||||
};
|
||||
|
||||
type DimensionProps = {
|
||||
@ -117,7 +118,7 @@ export const parseBuilder = async (ctx: Context, next: Next) => {
|
||||
let hasAgg = false;
|
||||
|
||||
measures.forEach((measure: MeasureProps & { field: string }) => {
|
||||
const { field, aggregation, alias } = measure;
|
||||
const { field, aggregation, alias, distinct } = measure;
|
||||
const attribute = [];
|
||||
const col = sequelize.col(field);
|
||||
if (aggregation) {
|
||||
@ -125,7 +126,7 @@ export const parseBuilder = async (ctx: Context, next: Next) => {
|
||||
throw new Error(`Invalid aggregation function: ${aggregation}`);
|
||||
}
|
||||
hasAgg = true;
|
||||
attribute.push(sequelize.fn(aggregation, col));
|
||||
attribute.push(sequelize.fn(aggregation, distinct ? sequelize.fn('DISTINCT', col) : col));
|
||||
} else {
|
||||
attribute.push(col);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user