Counting Records With Ecto
Sometimes you want to know how many records there are in a table. Ecto gives us a couple ways to approach this.
We can use the count\1
function that the Ecto query API provides.
Alternatively, we can use the fragment/1
function to use PostgreSQL's count
function.
Lastly, Ecto.Repo
has the aggregate/4
function which provides a :count
option.
Last updated