longevityframework / longevity

A Persistence Framework for Scala and NoSQL
http://longevityframework.org
Other
102 stars 6 forks source link

Support query aggregation #9

Open sullivan- opened 7 years ago

sullivan- commented 7 years ago

Support for query operations such as sum, ave, and groupBy. Something like:

// sketch

sealed trait AggregationOp
case object Sum extends AggregationOp
case object Ave extends AggregationOp
// ...

case class Aggregation[P, A](query: Query[P], op: AggregationOp, prop: Prop[P, A])
// add DSL for aggregation clauses
// we might need to add a tighter type here for queries that don't have offset/limit clauses

// add method to Repo something like this:
def aggregate[P](aggregation: Aggregation[P]): Future[A]

case class GroupBy[P, A, B](agg: Aggregation[P, A], prop: Prop[P, B]): Future[Seq[(A, B)]]
// of course it would be better if we could group multiple properties at once. this would require
// some migration to shapeless to preserve a list of B types.
// see https://www.pivotaltracker.com/story/show/140864207

It would probably be best to hold off on attempting this after the migration to shapeless.

We would have to target all three back ends here. But if you are interested in giving it a try, you can focus on a single back end. Once one is in place, I can help out with getting the other two back ends together. (Of course I am ready to help every step along the way, I just don't want you to be turned off by having to implement in three back ends.)