Skip to content

GroupBy fields

Andrey edited this page Aug 9, 2024 · 2 revisions

Since it's possible to mark fields as GroupBy attributes - aggregate fields are needed.

These structs are in module my_postgres::group_by_fields.

Example of GroupByDto

#[derive(SelectDbEntity, Debug)]
pub struct MinMaxKeySelectDto {
    #[group_by]
    pub candle_type: i64,
    #[group_by]
    pub instrument_id: String,
    pub is_bid: bool,

    #[db_column_name("date")]
    pub min: GroupByMin<i64>,
    #[db_column_name("date")]
    pub max: GroupByMax<i64>,
}

Which would generate SELECT statement

SELECT candle_type,instrument_id,is_bid,MIN(date)::bigint as "min",MAX(date)::bigint as "max" 

Clone this wiki locally