Ecto: return a count of records
To handle aggregates in Ecto there is a utility function we can leverage on Repo
called aggregate/3
. This function takes three arguments but the third is optional:
- The database table name
- The desired aggregate operation (in this case count)
- A field to count
Below is an example of executing the function:
Repo.aggregate(“stores”, :count, :uuid)
=> 4