How to Fetch Survey Results Data
Explore how to fetch survey results by building Ecto queries and context functions to retrieve product names and average star ratings. Understand the separation of concerns by creating a query builder module and extending the catalog context to handle data retrieval cleanly and predictably.
We'll cover the following...
To go much further, we’re going to need data, so we’ll switch gears from the view and focus on the backend service. In order to render products and their average star ratings in a chart, the LiveView must be able to query for this data in the form of a list of product names and their associated average star ratings.
This will be a good time to practice good Phoenix design. We’ll add a new API function to the Catalog context to make requests to the database. Our context function will rely on new query functions in the core to extract exactly the data it needs. Separating these concerns will keep the codebase organized and beautiful.
How to shape the data with ecto
The format of the data ...