porting grouping to knex