WEBVTT

00:00.280 --> 00:03.640
OK so let's refresh what our master plan was here.

00:03.660 --> 00:09.690
The whole point of using faker was eventually we want to be able to insert 500 of these or we have an

00:09.720 --> 00:11.650
e-mail that's randomized.

00:11.820 --> 00:16.080
And we also want to have a date created at date that is randomized.

00:16.080 --> 00:17.530
So let's focus on that part.

00:17.910 --> 00:22.330
We saw just refresh your memory that we can do things like this.

00:22.410 --> 00:23.390
Let me get a comment.

00:23.400 --> 00:33.110
All of this into just run one line at the bottom which is cancel that log faker dot dot dot past and

00:33.120 --> 00:35.260
that just gives us data in the past.

00:35.280 --> 00:39.010
I think it's within a year and maybe two.

00:39.010 --> 00:41.940
And let's see what I'm screwing up here.

00:41.950 --> 00:50.070
That faker that date passed onto log and we'll go over to the correct terminal here and we'll run node.

00:50.190 --> 00:50.800
Yes.

00:51.960 --> 00:52.610
OK.

00:52.950 --> 00:54.020
Now we're getting a date.

00:54.060 --> 01:01.270
Now you may have noticed a problem here this date syntax which I'll put here just so we can take a look.

01:01.410 --> 01:03.010
It's not valid javascript as it is.

01:03.050 --> 01:07.060
It's complaining that this is not going to jive well with our database.

01:07.290 --> 01:14.100
Remember that our database I ask you is expecting something like this where we have the year just do

01:14.100 --> 01:14.200
it.

01:14.210 --> 01:19.880
Is your year year Dasch month month dash day day space minute.

01:19.900 --> 01:23.090
Everybody we have our hour minute minute second second.

01:23.920 --> 01:31.180
So sort of in the time part looks OK and we got all this stuff that we don't want the year though the

01:31.180 --> 01:33.930
month the day of the week.

01:34.150 --> 01:36.920
We don't want the month spelled out we just want the day.

01:36.970 --> 01:38.380
This is a problem.

01:38.770 --> 01:40.670
So to prove that it's problematic.

01:40.810 --> 01:45.380
Let's try something let's try taking this date right here.

01:45.550 --> 01:47.510
Monday April 24th 2017.

01:47.670 --> 01:51.820
Copy it over and let's insert it manually into my Eskew.

01:51.850 --> 01:52.990
Let's see what happens.

01:53.320 --> 02:01.330
So I'll do an insert into users who have e-mail and created at values.

02:01.960 --> 02:03.950
And we'll just pick a random e-mail.

02:04.060 --> 02:13.840
Let's do Dusty at gmail dot com comma and then we'll pass in this giant javascript date or the javascript

02:13.840 --> 02:17.180
style date string.

02:17.200 --> 02:19.630
What do you think will happen when we insert this.

02:19.630 --> 02:23.990
So I'm just going to paste it in and hit enter.

02:24.010 --> 02:25.170
All right one row affected.

02:25.210 --> 02:26.370
One warning.

02:26.380 --> 02:28.000
Well let's see what happened.

02:28.120 --> 02:31.360
Let's do a select star from users.

02:31.780 --> 02:42.250
Actually that's the like start from users where e-mail equals dusty at gmail dot com that created that

02:42.730 --> 02:45.450
is all screwed up it said to Tuesday year 0 0 0 0.

02:45.460 --> 02:48.230
It's a problem that's not going to work for us.

02:48.270 --> 02:48.900
It's wrong.

02:49.090 --> 02:49.740
Right.

02:50.020 --> 02:54.820
So that's proving to you all part of this is to show you that the javascript way of doing data that

02:54.820 --> 03:00.750
we get from faker is not compatible with my as well.

03:00.880 --> 03:03.160
So let's just see what happens.

03:03.430 --> 03:04.780
I guess I can keep this here.

03:05.030 --> 03:08.550
Let's see what happens if we go to our app Jay.

03:08.560 --> 03:09.610
Yes.

03:10.540 --> 03:17.950
And we try and insert a person with a fake or date what do we get an error message or what happens.

03:17.980 --> 03:23.240
So we'll do this make some space here and rather than just e-mail.

03:23.260 --> 03:29.790
We'll also do created at which is faker date past.

03:29.850 --> 03:35.500
So the same thing we did down here which generated this date but now we're doing it dynamically here

03:35.500 --> 03:43.730
with an e-mail and it created that date both dynamic we're going to insert person using the same syntax.

03:44.680 --> 03:46.020
And let's see what happens.

03:46.470 --> 03:47.050
OK.

03:47.320 --> 03:48.700
Hold our breath here.

03:48.910 --> 03:52.950
Node APTA genius.

03:53.000 --> 03:54.960
And what do you know we don't get an error.

03:55.010 --> 03:56.200
So what's going on.

03:56.210 --> 03:57.350
Did it work.

03:57.380 --> 03:58.390
Let's come over here.

03:58.580 --> 04:05.510
Unfortunately we're not able to do our you know select star in order by created it because our Creator

04:05.510 --> 04:06.710
that date is now very.

04:06.740 --> 04:10.880
So it's no longer that the last one added in has the most recent date.

04:10.940 --> 04:13.700
So we'll just do a select star from users.

04:14.780 --> 04:19.880
And what we'll look for in my case I happen to know the data that we're working with.

04:19.880 --> 04:22.420
This was the one that was just added.

04:22.630 --> 04:24.580
Thirty eight years of course will be different.

04:24.740 --> 04:31.850
But notice that the date time created that isn't 0 0 0 0 like we had for Dusty This was the one where

04:31.850 --> 04:36.740
we manually took this the same exact thing coming from javascript.

04:37.160 --> 04:38.970
But we did it ourselves and it didn't work.

04:38.990 --> 04:45.270
But then when we used person instead of variable and then we use connection query and we passed it in.

04:45.440 --> 04:46.650
It somehow worked.

04:46.650 --> 04:49.570
And basically it comes down to the magic of this library.

04:49.790 --> 04:55.250
And I'm showing this to you to illustrate another point which is there's a lot of work that goes into

04:55.490 --> 05:00.100
sewing the stitches between something like node and my as well.

05:00.230 --> 05:08.320
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.

05:08.440 --> 05:08.720
OK.

05:08.720 --> 05:09.830
Here we go.

05:09.860 --> 05:15.650
If you look there's something right here that says date objects are converted to year year year year

05:15.650 --> 05:17.510
Dashon month month Desch day date.

05:17.510 --> 05:20.380
Basically the syntax we're looking for they're converted to that.

05:20.510 --> 05:28.610
So as part of this library it takes it upon itself to bridge my Escudo and notes it says all right if

05:28.610 --> 05:31.940
this is a javascript date which is what we're working with from faker.

05:32.090 --> 05:38.540
Well I know that the users are trying to insert it into my Escuela table that has no idea about javascript

05:38.540 --> 05:39.020
dates.

05:39.110 --> 05:41.700
So we're going to convert it before we send it.

05:41.780 --> 05:47.290
And then one other kind of interesting thing we can do is save this to a variable and we'll call it

05:47.360 --> 05:49.670
and results.

05:50.410 --> 06:00.840
And if I just do a canceled out log and result as well which again all new stuff I know it can be overwhelming.

06:00.860 --> 06:04.820
What this will do is show us that compiled sequel that is being sent over.

06:05.000 --> 06:10.010
So this is kind of before what person looks like and this will be an after.

06:10.100 --> 06:11.010
Let's take a look.

06:11.780 --> 06:12.920
Well if you go to node

06:15.970 --> 06:23.110
OK so you can see before we had created it looks like this Tuesday May it's the wrong format.

06:23.120 --> 06:30.410
That's javascript formant but some time before we actually sent this over it was converted to created

06:30.420 --> 06:34.500
that is equal to 20:16 dash 0 5 dash 24.

06:34.520 --> 06:37.750
And this is the correct my as well syntax.

06:38.270 --> 06:43.520
So this is kind of cool to be able to see the end result sequel that's being sent over.

06:43.640 --> 06:50.480
This is you know valid sequel that we could just copy this over and yeah it might look slightly different.

06:50.480 --> 06:58.070
These are a scaped which you do not have to do but if you notice this is sequel syntax and we could

06:58.070 --> 06:59.210
just paste that in.

06:59.600 --> 06:59.930
OK.

06:59.960 --> 07:03.400
So I'm going to get rid of that but I just want you to see that you could do that.

07:03.620 --> 07:08.540
And more importantly the whole point here was to show you that there's stuff happening behind the scenes

07:08.630 --> 07:13.710
which can be great and useful but it's also the stuff that you just don't know what's happening sometimes

07:13.820 --> 07:15.600
and you run into it you discover it.

07:15.800 --> 07:18.740
But it's the job of these libraries to connect the two.

07:18.770 --> 07:23.390
And there's a discrepancy in this case between how jobs could PENDELL States and how my school handles

07:23.390 --> 07:24.650
or expects of them.

07:24.650 --> 07:31.190
So behind the scenes this library that we're not writing we're not in charge of somebody is that library

07:31.190 --> 07:33.770
is patching them it's fixing it for us.

07:33.770 --> 07:34.210
OK.

07:34.460 --> 07:36.340
So we've inserted a single user.

07:36.350 --> 07:40.540
Now all we have left is to figure out how we insert 500 that's the next video.
