reminyborg / aggsy

Aggregation module/language for easy use in http query strings
MIT License
3 stars 1 forks source link

Be able to group on nested "array-object-properties" #7

Open Operacy opened 8 years ago

Operacy commented 8 years ago

With an array like:

var people = [
{ name: 'Bill', friends: [ {name: 'John', city:'Tokyo'}, {name: 'Jane', city: 'London'} ] },
{ name: 'Bob', friends: [ {name: 'Kotomi', city:'Tokyo'}, {name: 'Bruce', city: 'New York'} ] }
]

Aggsy should be able to group by friends.city - maybe by aggsy('friends.city()', people) ?

Returning:

{
  'Tokyo': [ 
    { name: 'Bill', friends: [ {name: 'John', city:'Tokyo'} ] },
    { name: 'Bob', friends: [ {name: 'Kotomi', city:'Tokyo'} ] }
  ],
  'London': [
    { name: 'Bill', friends: [ {name: 'Jane', city: 'London'} ] }
  ],
  'New York': [
    { name: 'Bob', friends: [ {name: 'Bruce', city: 'New York'} ] }
  ]
}

So aggsy('friends.city(_count()), people) makes sense..

reminyborg commented 2 years ago

You can already today use friends.city(_count()) as long as friends is not an array. Thinking the best way to do this would be to support: friends[].city(_count()) so that aggsy knows that an array is expected.