martenframework / marten

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

Add the ability to count records using specific columns in query sets #95

Closed ellmetha closed 10 months ago

ellmetha commented 1 year ago

Description

Presently it is possible to count all the records of a query set by relying on the #count method:

# Number of published articles:
Article.filter(published: true).count

It would be interesting to provide the ability to specify a field name to this method in order to count the number of records for which the specified field has a value in the database:

# Number of articles whose subtitle is present:
Article.filter(published: true).count(:subtitle)