OK so let's refresh what our master plan was here.
The whole point of using faker was eventually we want to be able to insert 500 of these or we have an
e-mail that's randomized.
And we also want to have a date created at date that is randomized.
So let's focus on that part.
We saw just refresh your memory that we can do things like this.
Let me get a comment.
All of this into just run one line at the bottom which is cancel that log faker dot dot dot past and
that just gives us data in the past.
I think it's within a year and maybe two.
And let's see what I'm screwing up here.
That faker that date passed onto log and we'll go over to the correct terminal here and we'll run node.
Yes.
OK.
Now we're getting a date.
Now you may have noticed a problem here this date syntax which I'll put here just so we can take a look.
It's not valid javascript as it is.
It's complaining that this is not going to jive well with our database.
Remember that our database I ask you is expecting something like this where we have the year just do
it.
Is your year year Dasch month month dash day day space minute.
Everybody we have our hour minute minute second second.
So sort of in the time part looks OK and we got all this stuff that we don't want the year though the
month the day of the week.
We don't want the month spelled out we just want the day.
This is a problem.
So to prove that it's problematic.
Let's try something let's try taking this date right here.
Monday April 24th 2017.
Copy it over and let's insert it manually into my Eskew.
Let's see what happens.
So I'll do an insert into users who have e-mail and created at values.
And we'll just pick a random e-mail.
Let's do Dusty at gmail dot com comma and then we'll pass in this giant javascript date or the javascript
style date string.
What do you think will happen when we insert this.
So I'm just going to paste it in and hit enter.
All right one row affected.
One warning.
Well let's see what happened.
Let's do a select star from users.
Actually that's the like start from users where e-mail equals dusty at gmail dot com that created that
is all screwed up it said to Tuesday year 0 0 0 0.
It's a problem that's not going to work for us.
It's wrong.
Right.
So that's proving to you all part of this is to show you that the javascript way of doing data that
we get from faker is not compatible with my as well.
So let's just see what happens.
I guess I can keep this here.
Let's see what happens if we go to our app Jay.
Yes.
And we try and insert a person with a fake or date what do we get an error message or what happens.
So we'll do this make some space here and rather than just e-mail.
We'll also do created at which is faker date past.
So the same thing we did down here which generated this date but now we're doing it dynamically here
with an e-mail and it created that date both dynamic we're going to insert person using the same syntax.
And let's see what happens.
OK.
Hold our breath here.
Node APTA genius.
And what do you know we don't get an error.
So what's going on.
Did it work.
Let's come over here.
Unfortunately we're not able to do our you know select star in order by created it because our Creator
that date is now very.
So it's no longer that the last one added in has the most recent date.
So we'll just do a select star from users.
And what we'll look for in my case I happen to know the data that we're working with.
This was the one that was just added.
Thirty eight years of course will be different.
But notice that the date time created that isn't 0 0 0 0 like we had for Dusty This was the one where
we manually took this the same exact thing coming from javascript.
But we did it ourselves and it didn't work.
But then when we used person instead of variable and then we use connection query and we passed it in.
It somehow worked.
And basically it comes down to the magic of this library.
And I'm showing this to you to illustrate another point which is there's a lot of work that goes into
sewing the stitches between something like node and my as well.
So if we go to the docs here if we do a search for I'll just do date time and I think it's down.
OK.
Here we go.
If you look there's something right here that says date objects are converted to year year year year
Dashon month month Desch day date.
Basically the syntax we're looking for they're converted to that.
So as part of this library it takes it upon itself to bridge my Escudo and notes it says all right if
this is a javascript date which is what we're working with from faker.
Well I know that the users are trying to insert it into my Escuela table that has no idea about javascript
dates.
So we're going to convert it before we send it.
And then one other kind of interesting thing we can do is save this to a variable and we'll call it
and results.
And if I just do a canceled out log and result as well which again all new stuff I know it can be overwhelming.
What this will do is show us that compiled sequel that is being sent over.
So this is kind of before what person looks like and this will be an after.
Let's take a look.
Well if you go to node
OK so you can see before we had created it looks like this Tuesday May it's the wrong format.
That's javascript formant but some time before we actually sent this over it was converted to created
that is equal to 20:16 dash 0 5 dash 24.
And this is the correct my as well syntax.
So this is kind of cool to be able to see the end result sequel that's being sent over.
This is you know valid sequel that we could just copy this over and yeah it might look slightly different.
These are a scaped which you do not have to do but if you notice this is sequel syntax and we could
just paste that in.
OK.
So I'm going to get rid of that but I just want you to see that you could do that.
And more importantly the whole point here was to show you that there's stuff happening behind the scenes
which can be great and useful but it's also the stuff that you just don't know what's happening sometimes
and you run into it you discover it.
But it's the job of these libraries to connect the two.
And there's a discrepancy in this case between how jobs could PENDELL States and how my school handles
or expects of them.
So behind the scenes this library that we're not writing we're not in charge of somebody is that library
is patching them it's fixing it for us.
OK.
So we've inserted a single user.
Now all we have left is to figure out how we insert 500 that's the next video.