Created
June 8, 2016 15:33
-
-
Save profh/f17e4dd0f238ce10f8724fdd91d30256 to your computer and use it in GitHub Desktop.
Using iex with BookManager app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Stepping through class example on BookManager | |
# Import Ecto.Query first, or none of this works in iex: | |
import Ecto.Query | |
# A simple example | |
query = from BookManager.Book | |
BookManager.Repo.all(query) | |
# Creating aliases because BookManager is just to long to keep rewriting: | |
alias BookManager.Publisher | |
alias BookManager.Author | |
alias BookManager.Book | |
alias BookManager.BookAuthor | |
alias BookManager.Repo | |
# Looking at the example above again: | |
query = from BookManager.Book | |
Repo.all(query) | |
Repo.all(Book) | |
# ... gives me the same result | |
# Building up queries: | |
Book |> Book.alphabetical | |
Book |> Book.alphabetical |> Book.this_century | |
# Now execute the query on our repo: | |
Book |> Book.alphabetical |> Book.this_century |> Repo.all | |
# Get a specific book: (! raises exception, no ! will return nil if missing) | |
dc = Repo.get_by!(Book, title: "The Divine Comedy") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment