So that's all in there, which is great.
Now what we want to do is insert, let's 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 500 at a time.
So all we're going to do is insert email and we'll leave off created.
For now, we'll just have it be the default.
So that means we'll have what do we want to do?
Let's do Katie three four at Yahoo.com and then we'll add in another one, which will be let's do a
tune day at gmail.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.
It looks good.
You can do a quick select star from users.
There we go.
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 Curr Time and now we're going to try and select from the user's
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 query 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 select star from users.
So we'll save that.
And again, you could just copy it and paste that right there.
I'm going to get rid of all of this because we're not working with time, date and now anymore.
All I'm going to do is say if there's an error, throw the error, and then we'll do console.log results
just like that.
So I'm going to 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 the database.
Then I have a queue which is just storing our simple select star from users.
Then I'm doing connection 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 console.log results.
So we need to go over to the correct terminal and run it.
Make sure we save have a circle up there.
So save node JS.
Okay.
Take a look at that.
We've got two results.
Each one is a row data packet with the email and it created that email and created it.
So that's looking good.
We are getting our data back and if we wanted to only take a look at day and his information, we can
drill down and just access results.
One, they're index at zero.
It's an array JavaScript.
So this is the zero width result and this is the first save run it again.
You can see we now are only dealing with tuned and if we only wanted to print out, let's say his email,
you can just do email and there we go to at gmail.com.
Okay, 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 500 or 1000 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 almost going to curse there, a really bad way, which would be basically select all the users
and then just run results dot length, which will tell us how many results there are, which gives us
two.
So that's a really bad way of doing it because if we have 10,000 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 dot 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 do count.
So count star 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 and as so we'll call
it as let's call it total this time and it needs to go here after the field before the from and now
if we run it again you can see it's stored under total and if we wanted to get that, it's just a matter
of results zero dot total.
And now we get to.
So this is a much better way because we're asking my SQL to count and just give us the count back.
We don't actually need every row.
So instead of 10,000 results back, just give us the 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.
It's probably just edit this.
Speed it up.
But when a user goes to this page, this number is the results of our node or node just running that
connection query, select count, star from users and whatever number comes back.
We are sticking in the markup in the HTML.