Skip to Main Content
Programming Phoenix
book

Programming Phoenix

by Chris McCord, Bruce Tate, Jose Valim
April 2016
Beginner to intermediate content levelBeginner to intermediate
300 pages
6h 58m
English
Pragmatic Bookshelf
Content preview from Programming Phoenix

Diving Deeper into Ecto Queries

So far, you know Ecto queries like a YouTube dog knows how to ride a bike. We’ve written our first query and we know that queries compose, but we still haven’t explored many concepts. It’s time to take off the training wheels and see more-advanced examples.

Open up IEx once more, and let’s retrieve a single user:

 iex>​ ​import​ Ecto.Query
 iex>​ alias Rumbl.Repo
 iex>​ alias Rumbl.User
 
 iex>​ username = ​"​​josevalim"
 "josevalim"
 
 iex>​ Repo.one(from u ​in​ User, ​where:​ u.username == ^username)
 ...
 %Rumbl.User{username: "josevalim", ...}

We’re using the same concepts you learned before:

  • Repo.one means return one row.

  • from u in User means we’re reading from the User schema.

  • where: u.username == ...

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

Programming Elm

Programming Elm

Jeremy Fairbank
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781680501926Errata Page