1 00:00:00,150 --> 00:00:00,490 Okay. 2 00:00:00,630 --> 00:00:04,920 So we saw the very basics of using faker, really just a single line. 3 00:00:05,010 --> 00:00:07,140 You know, it's a thing and that it's a package. 4 00:00:07,410 --> 00:00:12,840 Now, our game plan from here on out is to use Faker to generate our data for us. 5 00:00:12,870 --> 00:00:16,800 Get 500 users in there, but Faker on its own won't do that. 6 00:00:17,130 --> 00:00:20,160 So we'll use this fake Internet email. 7 00:00:20,490 --> 00:00:26,280 We want one of those or we want 500 of those, actually, and we'll use the date past. 8 00:00:26,280 --> 00:00:33,420 And the reason we need to use data passed is that when a user is created, yes, in the real world we 9 00:00:33,420 --> 00:00:37,170 want to store the current time when they actually signed up. 10 00:00:37,350 --> 00:00:43,140 But when we're inserting 500 fake users, we don't want them all to have the exact same time that they're 11 00:00:43,140 --> 00:00:46,680 joining because then that throws off our data, right? 12 00:00:46,830 --> 00:00:49,840 Having 500 users who joined at the same exact instant. 13 00:00:49,860 --> 00:00:54,060 So we'd much rather spread them out so that we could try certain things with the data, play around 14 00:00:54,060 --> 00:00:54,450 with it. 15 00:00:54,450 --> 00:00:56,660 So we're going to generate dates using this. 16 00:00:56,670 --> 00:01:02,010 So then the next logical question is, okay, we know how to generate a single email and a single date. 17 00:01:02,220 --> 00:01:04,069 How do we do 500 of them? 18 00:01:04,080 --> 00:01:08,370 And more importantly, how the heck do we get them in a MySQL database? 19 00:01:09,060 --> 00:01:11,610 So warning up here, red letters. 20 00:01:11,610 --> 00:01:13,740 This is not really code that will work. 21 00:01:13,950 --> 00:01:15,600 Well, it's not code that will work. 22 00:01:15,630 --> 00:01:16,830 That will work at all. 23 00:01:16,830 --> 00:01:20,820 But I just wanted to show you, we would want to do something like this, right? 24 00:01:21,090 --> 00:01:29,140 Insert into user's email and create a that and the values we want a fake internet email and fake date 25 00:01:29,340 --> 00:01:29,980 passed. 26 00:01:30,120 --> 00:01:34,170 This is sort of a hybrid between MySQL and Node. 27 00:01:34,200 --> 00:01:37,560 Unfortunately, this doesn't work, but this is what we're going for. 28 00:01:37,600 --> 00:01:37,940 Right. 29 00:01:37,950 --> 00:01:39,660 We want to do something like this. 30 00:01:39,840 --> 00:01:43,820 Insert 500 of these where we get a fake email and a fake date. 31 00:01:43,830 --> 00:01:46,230 The problem is insert into users. 32 00:01:46,230 --> 00:01:51,380 This syntax only exists in my SQL and faker only exists in Node. 33 00:01:51,390 --> 00:01:53,490 So how do we bridge that connection? 34 00:01:54,630 --> 00:01:57,330 Oh, and we want to do that 500 times, right? 35 00:01:57,480 --> 00:02:01,280 The answer is that we use something called my SQL. 36 00:02:01,290 --> 00:02:05,370 And it's confusing because it's a node package like Faker. 37 00:02:05,370 --> 00:02:07,710 It's another package called MySQL. 38 00:02:07,800 --> 00:02:14,390 What it does is it connects to MySQL, the actual database, and it talks to it. 39 00:02:14,400 --> 00:02:15,610 So every language. 40 00:02:15,630 --> 00:02:17,490 There are a couple of different packages. 41 00:02:17,780 --> 00:02:20,010 You know, PHP has a way of talking to mice. 42 00:02:20,040 --> 00:02:22,820 My SQL Ruby has a couple of ways. 43 00:02:22,830 --> 00:02:24,760 They are kind of adapters. 44 00:02:24,780 --> 00:02:28,440 Think of it as a connector between the two, a tube or a pipeline. 45 00:02:28,530 --> 00:02:33,030 And there's a couple for Node, but the one we're using is the most popular. 46 00:02:33,030 --> 00:02:36,560 It's called MySQL, which personally I find kind of confusing. 47 00:02:36,570 --> 00:02:43,500 I wish it was called my SQL node or my SQL Connector or my SQL JRS or something. 48 00:02:43,500 --> 00:02:46,350 And here's a couple of diagrams of basically how it works. 49 00:02:46,350 --> 00:02:48,280 So we have Node on its own. 50 00:02:48,300 --> 00:02:53,040 This is where we've been working, and then we have MySQL on its own, our separate database. 51 00:02:53,920 --> 00:02:55,960 So this has our data stored in it. 52 00:02:56,050 --> 00:03:03,490 And the MySQL package will be able to say things like, Hey, my SQL database, how many users are in 53 00:03:03,490 --> 00:03:03,880 there? 54 00:03:05,160 --> 00:03:10,350 Ask it to the database and then the MySQL database will be able to say, well, looks like there are 55 00:03:10,350 --> 00:03:17,880 currently 518 users, send that back to Node and we can use it or it might be something like this. 56 00:03:18,480 --> 00:03:20,070 Hey there, my SQL database. 57 00:03:20,070 --> 00:03:21,480 How many users are in there? 58 00:03:21,630 --> 00:03:24,900 And my SQL might say users. 59 00:03:24,900 --> 00:03:26,460 I have no idea what you're talking about. 60 00:03:26,460 --> 00:03:33,840 I don't have a user's table in here, in which case we would get that back to Node.js, and we'd be 61 00:03:33,840 --> 00:03:36,280 able to know that because of the package we're using. 62 00:03:36,300 --> 00:03:40,010 My SQL package is both asking the questions, right? 63 00:03:40,020 --> 00:03:43,650 It's querying the database and it's handling the replies. 64 00:03:43,800 --> 00:03:49,080 So then in here we can write logic that says, okay, if we don't get a response, if there's an error 65 00:03:49,080 --> 00:03:55,440 message, let's do one thing, otherwise do something else or a third scenario. 66 00:03:56,010 --> 00:04:02,910 Hey there, MySQL our adapter or MySQL Connector might ask how many users are in your database? 67 00:04:03,210 --> 00:04:05,670 And there is no database. 68 00:04:05,820 --> 00:04:07,350 We don't get a response. 69 00:04:07,350 --> 00:04:09,960 Well, we need to figure out how to handle that in Node. 70 00:04:09,960 --> 00:04:13,950 And fortunately, fortunately, the MySQL package handles that. 71 00:04:13,950 --> 00:04:16,290 So it will start by freaking out. 72 00:04:16,290 --> 00:04:17,000 Are you there? 73 00:04:17,010 --> 00:04:17,970 What's going on? 74 00:04:18,000 --> 00:04:21,209 Bunch of sad faces, but then it will figure it out. 75 00:04:21,209 --> 00:04:26,280 It will basically time out and it will figure out there's no connection, there's no database there, 76 00:04:26,280 --> 00:04:29,910 and we'll be able to handle that as well, which is something that could happen. 77 00:04:29,910 --> 00:04:33,450 Your database server could go down, something could go wrong. 78 00:04:33,630 --> 00:04:36,120 So these are different scenarios. 79 00:04:36,120 --> 00:04:41,100 Mainly we're working with this one right where there's good communication and everything's working how 80 00:04:41,100 --> 00:04:41,730 it should. 81 00:04:42,240 --> 00:04:49,560 But the key thing is that the package MySQL package works and node talks to a database. 82 00:04:49,560 --> 00:04:52,560 So without further ado, let's see how that works.