1 00:00:00,090 --> 00:00:01,950 So that's all in there, which is great. 2 00:00:02,100 --> 00:00:07,770 Now what we want to do is insert, let's say, just two users just so that we have something. 3 00:00:08,070 --> 00:00:10,710 So we'll do an insert into users. 4 00:00:11,220 --> 00:00:16,800 This will be one of the last times we're actually inserting stuff manually rather than using our code 5 00:00:16,800 --> 00:00:19,950 to do it for us and inserting 500 at a time. 6 00:00:20,100 --> 00:00:26,150 So all we're going to do is insert email and we'll leave off created. 7 00:00:26,280 --> 00:00:28,590 For now, we'll just have it be the default. 8 00:00:30,340 --> 00:00:33,950 So that means we'll have what do we want to do? 9 00:00:33,970 --> 00:00:46,090 Let's do Katie three four at Yahoo.com and then we'll add in another one, which will be let's do a 10 00:00:46,390 --> 00:00:51,350 tune day at gmail.com. 11 00:00:51,370 --> 00:00:52,000 Sure. 12 00:00:52,030 --> 00:00:52,960 Just like that. 13 00:00:53,500 --> 00:00:54,940 So just two users. 14 00:00:54,940 --> 00:00:58,390 I'm not going to source this again unless I commented this out. 15 00:00:58,390 --> 00:01:00,580 Otherwise it would try and create users again. 16 00:01:00,610 --> 00:01:01,900 Just copy this. 17 00:01:01,930 --> 00:01:03,610 Do we have any syntax issues? 18 00:01:03,790 --> 00:01:04,450 We'll see. 19 00:01:05,410 --> 00:01:06,320 It looks good. 20 00:01:06,340 --> 00:01:09,040 You can do a quick select star from users. 21 00:01:09,790 --> 00:01:10,510 There we go. 22 00:01:10,990 --> 00:01:12,280 So we have data in here. 23 00:01:12,310 --> 00:01:13,780 That's all we need to start. 24 00:01:14,350 --> 00:01:17,860 Now, our goal is to come over to this file. 25 00:01:18,340 --> 00:01:25,630 And rather than doing these silly select Curr Time and now we're going to try and select from the user's 26 00:01:25,630 --> 00:01:26,120 table. 27 00:01:26,140 --> 00:01:31,000 We want to make sure that not only are we connecting to the database, which we've already established, 28 00:01:31,000 --> 00:01:35,290 but we want to see if we are able to connect with that table and query it. 29 00:01:35,440 --> 00:01:39,070 And the syntax is actually the same. 30 00:01:39,070 --> 00:01:40,750 So I have a slide on it. 31 00:01:40,750 --> 00:01:46,480 But if you notice, we're just doing connection query and then we just have a query here that we can 32 00:01:46,480 --> 00:01:47,890 replace with whatever we want. 33 00:01:48,070 --> 00:01:50,170 So our query is what? 34 00:01:50,170 --> 00:01:52,050 How do we select everything from users? 35 00:01:52,060 --> 00:01:56,020 Well, we just did it select star from users. 36 00:01:56,290 --> 00:01:57,700 So we'll save that. 37 00:01:58,450 --> 00:02:02,320 And again, you could just copy it and paste that right there. 38 00:02:02,650 --> 00:02:06,700 I'm going to get rid of all of this because we're not working with time, date and now anymore. 39 00:02:06,790 --> 00:02:15,580 All I'm going to do is say if there's an error, throw the error, and then we'll do console.log results 40 00:02:16,180 --> 00:02:17,170 just like that. 41 00:02:17,410 --> 00:02:19,270 So I'm going to get rid of everything else here. 42 00:02:19,300 --> 00:02:20,290 Just these. 43 00:02:20,440 --> 00:02:22,420 So this is just set up. 44 00:02:22,420 --> 00:02:24,700 We're not even using faker can get rid of that. 45 00:02:25,240 --> 00:02:27,370 All that I'm doing, connecting to the database. 46 00:02:27,430 --> 00:02:32,110 Then I have a queue which is just storing our simple select star from users. 47 00:02:32,530 --> 00:02:34,420 Then I'm doing connection query. 48 00:02:34,420 --> 00:02:36,130 So take this connection we set up. 49 00:02:37,460 --> 00:02:41,680 Run this query, which the first argument is select start from users. 50 00:02:41,690 --> 00:02:43,820 The second argument is everything. 51 00:02:43,820 --> 00:02:47,870 Basically, it's a function that will be called when our query finishes. 52 00:02:48,170 --> 00:02:53,810 So when it either comes back saying Great, it worked, or it comes back saying, Hey, your database 53 00:02:53,810 --> 00:02:58,880 isn't running, or I can't find that table, whatever it is, if there's an error, throw the error. 54 00:02:58,880 --> 00:03:01,550 If there is no error, this is empty. 55 00:03:02,060 --> 00:03:03,050 There will be nothing there. 56 00:03:04,450 --> 00:03:06,240 And console.log results. 57 00:03:06,250 --> 00:03:10,390 So we need to go over to the correct terminal and run it. 58 00:03:10,600 --> 00:03:12,520 Make sure we save have a circle up there. 59 00:03:12,520 --> 00:03:15,520 So save node JS. 60 00:03:16,590 --> 00:03:17,040 Okay. 61 00:03:17,100 --> 00:03:18,030 Take a look at that. 62 00:03:18,240 --> 00:03:19,890 We've got two results. 63 00:03:19,920 --> 00:03:25,920 Each one is a row data packet with the email and it created that email and created it. 64 00:03:26,280 --> 00:03:27,350 So that's looking good. 65 00:03:27,360 --> 00:03:36,060 We are getting our data back and if we wanted to only take a look at day and his information, we can 66 00:03:36,060 --> 00:03:38,250 drill down and just access results. 67 00:03:38,250 --> 00:03:40,230 One, they're index at zero. 68 00:03:40,230 --> 00:03:41,700 It's an array JavaScript. 69 00:03:41,700 --> 00:03:47,670 So this is the zero width result and this is the first save run it again. 70 00:03:48,360 --> 00:03:54,180 You can see we now are only dealing with tuned and if we only wanted to print out, let's say his email, 71 00:03:54,540 --> 00:03:58,850 you can just do email and there we go to at gmail.com. 72 00:03:59,220 --> 00:04:04,710 Okay, so that's the first and most basic thing that we can do as far as selecting. 73 00:04:05,070 --> 00:04:10,440 So now when we're talking about this join us application that we're making, we're never actually selecting 74 00:04:10,440 --> 00:04:11,760 all the user information. 75 00:04:11,760 --> 00:04:15,090 We're going to have 500 or 1000 users, ideally more. 76 00:04:15,210 --> 00:04:17,040 We're not selecting all of them. 77 00:04:17,220 --> 00:04:20,700 What we're trying to display to the user is just how many there are. 78 00:04:21,209 --> 00:04:25,920 We're trying to display how many users there are, and that is just a matter of counting. 79 00:04:25,920 --> 00:04:28,950 Now, we could do it a really kind of bad way. 80 00:04:29,760 --> 00:04:35,280 I was almost going to curse there, a really bad way, which would be basically select all the users 81 00:04:35,400 --> 00:04:42,990 and then just run results dot length, which will tell us how many results there are, which gives us 82 00:04:42,990 --> 00:04:43,680 two. 83 00:04:43,860 --> 00:04:50,010 So that's a really bad way of doing it because if we have 10,000 items in our database, we're going 84 00:04:50,010 --> 00:04:55,320 to go select all of them, bring all of them back here just so that we can do dot length on it. 85 00:04:55,320 --> 00:04:57,000 I don't think that's a good way of doing it. 86 00:04:57,090 --> 00:05:02,010 So rather than doing that, what we can do instead is just do count. 87 00:05:02,010 --> 00:05:06,180 So count star from users, just like we've done before. 88 00:05:06,870 --> 00:05:14,220 Now if we do it you can see we get count is two and a nice remember we can add in and as so we'll call 89 00:05:14,220 --> 00:05:22,050 it as let's call it total this time and it needs to go here after the field before the from and now 90 00:05:22,050 --> 00:05:27,000 if we run it again you can see it's stored under total and if we wanted to get that, it's just a matter 91 00:05:27,000 --> 00:05:29,580 of results zero dot total. 92 00:05:31,750 --> 00:05:32,930 And now we get to. 93 00:05:32,950 --> 00:05:37,960 So this is a much better way because we're asking my SQL to count and just give us the count back. 94 00:05:37,960 --> 00:05:39,600 We don't actually need every row. 95 00:05:39,610 --> 00:05:44,830 So instead of 10,000 results back, just give us the count and then we can work with that. 96 00:05:44,830 --> 00:05:46,390 So this is what we'll be doing. 97 00:05:46,390 --> 00:05:51,490 We will have a query like this when a user goes to the home page of our application. 98 00:05:52,270 --> 00:05:53,530 Bear with me while I scroll back. 99 00:05:54,940 --> 00:05:56,080 It's probably just edit this. 100 00:05:56,200 --> 00:05:56,920 Speed it up. 101 00:05:58,560 --> 00:06:06,180 But when a user goes to this page, this number is the results of our node or node just running that 102 00:06:06,180 --> 00:06:12,000 connection query, select count, star from users and whatever number comes back. 103 00:06:12,000 --> 00:06:15,150 We are sticking in the markup in the HTML.