Finding top users with aggregates

In the current ElixirDrip application, there are four users, jose, xpto, daniel, and andre:

iex> Repo.all(from u in User, select: map(u, [:id, :username, :email]))10:48:41.609 [debug] QUERY OK source="users" db=7.4ms queue=0.1msSELECT u0."id", u0."username", u0."email" FROM "users" AS u0 [][  %{email: "jose@hey.ho", id: "13KvtrMQ9uRB8MqkJpKSSQZxnBa", username:   "jose"},  %{email: "xp@to.foo", id: "13ix90kpmblgJF4Ful762gqb6m2", username:   "xpto"},  %{email: "daniel@right.here", id: "13ucVBdFw40QqbYjwm65jEml7P9",   username: "daniel"},  %{email: "andre@somewhere.com", id: "13ucZ46LTdsfvezCPviNJ96gYqu",   username: "andre"}]

Notice how we are using the Query.API.map/2 function for Ecto to select the results into a ...

Get Mastering Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.