Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content