Composing Queries
With the addition of join we can start doing some larger and more detailed queries. This is a good time to look at one of the features of Query that simplifies working with complicated queries: composability. Ecto allows us to break up large queries into smaller pieces that can be reassembled at will. This makes them easier to work with, and allows you to re-use parts of queries in more than one place. This next section will show you exactly how to do that, and along the way, you’ll learn a little bit more about how queries are constructed under the hood.
Let’s say that we wanted to look up all of the albums by Miles Davis. Using joins, this query is straightforward:
| q = from a in "albums" ... |
Get Programming Ecto 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.