Okay.
So we saw the very basics of using faker, really just a single line.
You know, it's a thing and that it's a package.
Now, our game plan from here on out is to use Faker to generate our data for us.
Get 500 users in there, but Faker on its own won't do that.
So we'll use this fake Internet email.
We want one of those or we want 500 of those, actually, and we'll use the date past.
And the reason we need to use data passed is that when a user is created, yes, in the real world we
want to store the current time when they actually signed up.
But when we're inserting 500 fake users, we don't want them all to have the exact same time that they're
joining because then that throws off our data, right?
Having 500 users who joined at the same exact instant.
So we'd much rather spread them out so that we could try certain things with the data, play around
with it.
So we're going to generate dates using this.
So then the next logical question is, okay, we know how to generate a single email and a single date.
How do we do 500 of them?
And more importantly, how the heck do we get them in a MySQL database?
So warning up here, red letters.
This is not really code that will work.
Well, it's not code that will work.
That will work at all.
But I just wanted to show you, we would want to do something like this, right?
Insert into user's email and create a that and the values we want a fake internet email and fake date
passed.
This is sort of a hybrid between MySQL and Node.
Unfortunately, this doesn't work, but this is what we're going for.
Right.
We want to do something like this.
Insert 500 of these where we get a fake email and a fake date.
The problem is insert into users.
This syntax only exists in my SQL and faker only exists in Node.
So how do we bridge that connection?
Oh, and we want to do that 500 times, right?
The answer is that we use something called my SQL.
And it's confusing because it's a node package like Faker.
It's another package called MySQL.
What it does is it connects to MySQL, the actual database, and it talks to it.
So every language.
There are a couple of different packages.
You know, PHP has a way of talking to mice.
My SQL Ruby has a couple of ways.
They are kind of adapters.
Think of it as a connector between the two, a tube or a pipeline.
And there's a couple for Node, but the one we're using is the most popular.
It's called MySQL, which personally I find kind of confusing.
I wish it was called my SQL node or my SQL Connector or my SQL JRS or something.
And here's a couple of diagrams of basically how it works.
So we have Node on its own.
This is where we've been working, and then we have MySQL on its own, our separate database.
So this has our data stored in it.
And the MySQL package will be able to say things like, Hey, my SQL database, how many users are in
there?
Ask it to the database and then the MySQL database will be able to say, well, looks like there are
currently 518 users, send that back to Node and we can use it or it might be something like this.
Hey there, my SQL database.
How many users are in there?
And my SQL might say users.
I have no idea what you're talking about.
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
able to know that because of the package we're using.
My SQL package is both asking the questions, right?
It's querying the database and it's handling the replies.
So then in here we can write logic that says, okay, if we don't get a response, if there's an error
message, let's do one thing, otherwise do something else or a third scenario.
Hey there, MySQL our adapter or MySQL Connector might ask how many users are in your database?
And there is no database.
We don't get a response.
Well, we need to figure out how to handle that in Node.
And fortunately, fortunately, the MySQL package handles that.
So it will start by freaking out.
Are you there?
What's going on?
Bunch of sad faces, but then it will figure it out.
It will basically time out and it will figure out there's no connection, there's no database there,
and we'll be able to handle that as well, which is something that could happen.
Your database server could go down, something could go wrong.
So these are different scenarios.
Mainly we're working with this one right where there's good communication and everything's working how
it should.
But the key thing is that the package MySQL package works and node talks to a database.
So without further ado, let's see how that works.