Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
The first step in planning our database is to answer two fundamental questions: what entities are we keeping track of, and how are they related to one another? While answering these questions before implementing a datastore is not always possible, if we can do it, we absolutely should, because doing so will reduce time and complexity for us down the road.
[MUSIC] 0:00 Now that we have our routes coded, we need to perform operations on data. 0:04 That starts with getting a clear picture of the data our API will be handling. 0:10 The first step in planning our database is to answer two fundamental questions. 0:15 What entities are we keeping track of? 0:21 And how are they related to one another? 0:23 The entities we're tracking are questions and answers. 0:26 Our question will need the text of the question, 0:30 which will be represented by a string. 0:33 The question will need a created app property and 0:36 date to mark the time when questions are posted. 0:39 Questions can then be sorted chronologically. 0:43 Answers would contain the text of the answer as a string 0:46 as well as a creation time. 0:50 Since we are allowing users to edit answers, 0:53 let's also store the time when the answer was last updated. 0:56 Just like the created at time, the updated at time can be helpful in sorting. 1:00 But some answers will be stored as a number. 1:06 Now that we have a clear picture of the data we want to track, 1:09 let's look at the second question, how are these entities related? 1:13 Answers depend on the existence of a question 1:18 often referred to as a parent child relationship. 1:21 There can be many answers associated with a question, but 1:24 only one question associated with an answer. 1:28 Now that we've got a picture of what entities we want to store in our database 1:31 and how they are related to each other, we're in a great shape to start 1:35 thinking about the database itself and how to talk to it effectively. 1:39
You need to sign up for Treehouse in order to download course files.Sign up