So that's all in there which is great.
Now what we want to do is insert say just two users just so that we have something.
So we'll do an insert into users.
This will be one of the last times we're actually inserting stuff manually rather than using our code
to do it for us and inserting you know 500 at a time.
So all we're going to do is insert email and we'll leave off created after now we'll just have it be
the default.
So that means we'll have what we want to do.
Let's do Katie three 4 at yahoo dot com.
And then adding another one which will be let's do today at gmail dot com.
Sure just like that.
So just two users.
I'm not going to source this again unless I commented this out otherwise it would try and create users
again just copy this.
Do we have any syntax issues.
We'll see.
OK.
It looks good.
You can do a quick select star from users.
There we go.
OK.
So we have data in here.
That's all we need to start now.
Our goal is to come over to this file and rather than doing these silly select her time and her date
and now we're going to try and select from the users table we want to make sure that not only are we
connecting to the database which we've already established but we want to see if we are able to connect
with that table and query it.
And the syntax is actually the same.
So I have a slide on it but if you notice we're just doing connection queery and then we just have a
query here that we can replace with whatever we want.
So our query is what how do we select everything from users.
Well we just did it.
It's like star from users.
So we'll save that.
And you know again you could just copy and paste that right there.
I'm going to get rid of all this because we're not working with time date now anymore.
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
just like that.
I mean get rid of everything else here just these.
So this is just set up we're not even using faker can get rid of that.
All that I'm doing connecting to a database and I have a q which is just storing our simple select star
from users.
Then I'm doing connection's query.
So take this connection we set up run this query which the first argument is select start from users.
The second argument is everything.
Basically it's a function that will be called when our query finishes.
So when it either comes back saying great it worked or it comes back saying hey your database isn't
running or I can't find that table whatever it is.
If there's an error throw the error if there is no error.
This is empty.
There will be nothing there.
And constantly log results.
So we need to go over to the correct terminal and run it make sure we save it a circle up there.
So save Noad apt.
James OK take a look at that.
We've got two results.
Each one is a row data packet with the email and it created that e-mail and created it.
So that's looking good.
We are getting our data back and if we want to only and take a look at toone day and his information
we can drill down and just access results 1 their index at zero.
It's an array Javascript.
So this is the zero with result.
And this is the first save.
Run it again.
You can see we now are only dealing with today.
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
dot com.
OK.
So that's the first and most basic thing that we can do as far as selecting.
So now when we're talking about this join us application that we're making we're never actually selecting
all the user information we're going to have five hundred or thousand users ideally more.
We're not selecting all of them.
What we're trying to display to the user is just how many there are.
We're trying to display how many users there are and that is just a matter of counting.
Now we could do it a really kind of bad way.
I was going to cursor a really bad way which would be basically select all the users and then just run
results.
Link which will tell us how many results that are which gives us two.
So that's a really bad way of doing it because if we have 10000 items in our database we're going to
go select all of them bring all of them back here just so that we can do data length on it.
I don't think that's a good way of doing it.
So rather than doing that what we can do instead is just to count its like count start from users just
like we've done before.
Now if we do it you can see we get count is two and a nice.
Remember we can add in as.
So we'll call it as lets call it total this time and it needs over here after the field before the from.
And now if we run it again I can see it stored under total.
And if we wanted to get that it's just a matter of results.
Not total and now we get to.
So this is a much better way because we're asking my as well to count and just give us the count back.
We don't actually need every row.
So instead of 10000 results back just give us count and then we can work with that.
So this is what we'll be doing.
We will have a query like this when a user goes to the home page of our application.
Bear with me while I scroll back to probably just edit this speeded up.
OK.
But when a user goes to this page this number is the result of our node or no Jasc running that connection
dot query select count star from users and whatever number comes back.
We are sticking in the markup in each team out.