martenframework / marten

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

Add the ability to query the minimum or maximum values of a given column in query sets #146

Closed ellmetha closed 6 months ago

ellmetha commented 7 months ago

Description

There is presently no easy way to query the minimum/maximum values of a given column - at the database level - by leveraging query sets. In order to palliate this, let's add new #minimum and #maximum methods to the base query set implementation. These new methods should take the name of a field for which the minimum/maximum value should be queried.

For example:

Person.all.minimum(:id) # => 1
Person.all.maximum(:id) # => 145012345

These methods should also be available from model classes directly:

Person.minimum(:id) # => 1
Person.maximum(:id) # => 145012345