martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
405 stars 23 forks source link

Add the ability to compute the average of a given column in query sets #144

Closed ellmetha closed 7 months ago

ellmetha commented 7 months ago

Description

There is presently no easy way to average the values of a given column - at the database level - by leveraging query sets. In order to palliate this, let's add a new #average method to the base query set implementation. This new method should take the name of a field for which the average should be computed.

For example:

Person.all.average(:age) # => 33.6