WEBVTT

00:00.120 --> 00:02.230
So that's all in there which is great.

00:02.250 --> 00:08.120
Now what we want to do is insert say just two users just so that we have something.

00:08.220 --> 00:11.210
So we'll do an insert into users.

00:11.310 --> 00:16.770
This will be one of the last times we're actually inserting stuff manually rather than using our code

00:16.770 --> 00:20.000
to do it for us and inserting you know 500 at a time.

00:20.250 --> 00:27.630
So all we're going to do is insert email and we'll leave off created after now we'll just have it be

00:27.630 --> 00:30.350
the default.

00:30.410 --> 00:33.930
So that means we'll have what we want to do.

00:33.980 --> 00:40.120
Let's do Katie three 4 at yahoo dot com.

00:40.310 --> 00:51.440
And then adding another one which will be let's do today at gmail dot com.

00:51.440 --> 00:53.430
Sure just like that.

00:53.450 --> 00:55.160
So just two users.

00:55.160 --> 00:59.990
I'm not going to source this again unless I commented this out otherwise it would try and create users

00:59.990 --> 01:01.950
again just copy this.

01:01.970 --> 01:03.720
Do we have any syntax issues.

01:03.830 --> 01:04.600
We'll see.

01:04.900 --> 01:05.370
OK.

01:05.420 --> 01:06.270
It looks good.

01:06.410 --> 01:09.810
You can do a quick select star from users.

01:09.830 --> 01:10.500
There we go.

01:10.730 --> 01:10.970
OK.

01:10.970 --> 01:12.220
So we have data in here.

01:12.440 --> 01:15.020
That's all we need to start now.

01:15.050 --> 01:21.560
Our goal is to come over to this file and rather than doing these silly select her time and her date

01:21.560 --> 01:28.220
and now we're going to try and select from the users table we want to make sure that not only are we

01:28.220 --> 01:33.410
connecting to the database which we've already established but we want to see if we are able to connect

01:33.410 --> 01:35.410
with that table and query it.

01:35.630 --> 01:38.990
And the syntax is actually the same.

01:39.170 --> 01:44.390
So I have a slide on it but if you notice we're just doing connection queery and then we just have a

01:44.390 --> 01:48.150
query here that we can replace with whatever we want.

01:48.170 --> 01:52.180
So our query is what how do we select everything from users.

01:52.190 --> 01:53.160
Well we just did it.

01:53.360 --> 01:56.080
It's like star from users.

01:56.420 --> 01:57.910
So we'll save that.

01:58.640 --> 02:02.450
And you know again you could just copy and paste that right there.

02:02.780 --> 02:06.700
I'm going to get rid of all this because we're not working with time date now anymore.

02:06.950 --> 02:15.350
All I'm going to do is say if there's an error throw the error and then we'll do cancel that log results

02:16.280 --> 02:17.590
just like that.

02:17.660 --> 02:20.630
I mean get rid of everything else here just these.

02:20.630 --> 02:25.020
So this is just set up we're not even using faker can get rid of that.

02:25.310 --> 02:31.230
All that I'm doing connecting to a database and I have a q which is just storing our simple select star

02:31.230 --> 02:32.420
from users.

02:32.660 --> 02:34.390
Then I'm doing connection's query.

02:34.430 --> 02:41.870
So take this connection we set up run this query which the first argument is select start from users.

02:41.870 --> 02:43.790
The second argument is everything.

02:43.790 --> 02:48.350
Basically it's a function that will be called when our query finishes.

02:48.350 --> 02:53.990
So when it either comes back saying great it worked or it comes back saying hey your database isn't

02:53.990 --> 02:56.990
running or I can't find that table whatever it is.

02:57.140 --> 03:00.370
If there's an error throw the error if there is no error.

03:00.680 --> 03:02.090
This is empty.

03:02.090 --> 03:03.000
There will be nothing there.

03:04.540 --> 03:06.430
And constantly log results.

03:06.460 --> 03:12.600
So we need to go over to the correct terminal and run it make sure we save it a circle up there.

03:12.680 --> 03:14.800
So save Noad apt.

03:14.850 --> 03:18.320
James OK take a look at that.

03:18.420 --> 03:19.840
We've got two results.

03:20.040 --> 03:26.010
Each one is a row data packet with the email and it created that e-mail and created it.

03:26.310 --> 03:27.510
So that's looking good.

03:27.540 --> 03:34.800
We are getting our data back and if we want to only and take a look at toone day and his information

03:35.640 --> 03:40.200
we can drill down and just access results 1 their index at zero.

03:40.200 --> 03:41.660
It's an array Javascript.

03:41.670 --> 03:43.750
So this is the zero with result.

03:43.770 --> 03:46.860
And this is the first save.

03:46.860 --> 03:47.830
Run it again.

03:48.390 --> 03:50.930
You can see we now are only dealing with today.

03:51.160 --> 03:58.140
And if we only wanted to print out let's say it's email can just do email and there we go today at gmail

03:58.140 --> 03:58.930
dot com.

03:59.280 --> 03:59.760
OK.

03:59.880 --> 04:04.850
So that's the first and most basic thing that we can do as far as selecting.

04:05.220 --> 04:10.200
So now when we're talking about this join us application that we're making we're never actually selecting

04:10.530 --> 04:15.170
all the user information we're going to have five hundred or thousand users ideally more.

04:15.420 --> 04:17.200
We're not selecting all of them.

04:17.400 --> 04:21.080
What we're trying to display to the user is just how many there are.

04:21.300 --> 04:26.010
We're trying to display how many users there are and that is just a matter of counting.

04:26.040 --> 04:29.580
Now we could do it a really kind of bad way.

04:29.880 --> 04:36.540
I was going to cursor a really bad way which would be basically select all the users and then just run

04:36.930 --> 04:37.540
results.

04:37.600 --> 04:43.710
Link which will tell us how many results that are which gives us two.

04:44.070 --> 04:50.100
So that's a really bad way of doing it because if we have 10000 items in our database we're going to

04:50.100 --> 04:55.420
go select all of them bring all of them back here just so that we can do data length on it.

04:55.440 --> 04:56.980
I don't think that's a good way of doing it.

04:57.240 --> 05:05.040
So rather than doing that what we can do instead is just to count its like count start from users just

05:05.040 --> 05:06.960
like we've done before.

05:06.990 --> 05:11.880
Now if we do it you can see we get count is two and a nice.

05:11.890 --> 05:13.710
Remember we can add in as.

05:13.720 --> 05:21.760
So we'll call it as lets call it total this time and it needs over here after the field before the from.

05:21.760 --> 05:25.290
And now if we run it again I can see it stored under total.

05:25.460 --> 05:27.700
And if we wanted to get that it's just a matter of results.

05:28.200 --> 05:33.020
Not total and now we get to.

05:33.030 --> 05:37.950
So this is a much better way because we're asking my as well to count and just give us the count back.

05:37.950 --> 05:39.640
We don't actually need every row.

05:39.650 --> 05:44.970
So instead of 10000 results back just give us count and then we can work with that.

05:44.970 --> 05:46.410
So this is what we'll be doing.

05:46.500 --> 05:52.260
We will have a query like this when a user goes to the home page of our application.

05:52.260 --> 05:56.770
Bear with me while I scroll back to probably just edit this speeded up.

05:57.830 --> 05:58.280
OK.

05:58.560 --> 06:06.660
But when a user goes to this page this number is the result of our node or no Jasc running that connection

06:06.660 --> 06:12.060
dot query select count star from users and whatever number comes back.

06:12.120 --> 06:14.930
We are sticking in the markup in each team out.
