Choosing Queries1:47 with Ben Deitch
In this video we'll take a look at which queries we'll need to represent in our Data Access Objects!
We've created all of our entities, which represent the tables in our database. 0:00 Now it's time to create the data access objects, or 0:05 DAOs, which represent the queries we need for each of those tables. 0:08 But before we start creating anything, let's talk about what queries we need, and 0:12 which table those queries belong to. 0:16 In main activity, we display a list of all the pizzas. 0:20 To generate this list, 0:24 we'll need a query to select all the pizzas from the pizza table. 0:25 Once we select a pizza, we take that pizza's ID and 0:29 pass it into the creator activity. 0:32 Here, in order to display the pizza, we'll need to retrieve its name, 0:35 as well as which toppings are associated with that pizza. 0:38 To get the name, we'll use a query to return a pizza by its id, and 0:42 then just access the name property. 0:46 But to get which toppings are on a pizza, we'll actually need two queries. 0:49 [SOUND] One to get which topping ids belong with our pizza id, and 0:53 then another to get which toppings belong with those topping ids. 0:57 To populate the Recycler view at the bottom, 1:01 we'll also need a query to retrieve all the toppings. 1:03 Once a user has created their pizza, they'll probably want to save it. 1:06 To handle saving a pizza, we'll need two insert statements. 1:10 One for saving its data to the pizza table, and one for 1:14 saving its toppings to the pizza topping table. 1:16 Likewise, to let users delete a pizza, we'll need queries to remove a pizza from 1:20 both the pizza table, as well as the pizza topping table. 1:24 Last but not least, to let us populate our topping table, 1:27 we'll need an insert statement. 1:31 It may seem like a lot of queries, but 1:33 broken out into which queries along with which table, it's really not so bad. 1:35 Awesome, now that we know which queries we need to create, 1:41 let's start creating them in the next video. 1:44
You need to sign up for Treehouse in order to download course files.Sign up