OK so in the last video we got our Noad file javascript communicating with our minuscule database of
being very very simple communication we're not actually interacting with tables but this is secret code
that we're running.
So the next step of course is getting it to interact with tables.
So we're going to in this video we're going to create our table we're going to define our schema create
our table in my as well separate from javascript and then we're going to try and query it from here.
So basically we're going to go into my ask you Al Qaeda table let's add two or three users and then
we're going to see if we can fetch them from node.
But before we get there.
One thing I want to address very briefly is when we're looking at this code you know this connection
like queery function error results fields or this code appear far connection equals blah blah blah blah
blah.
You might be wondering how did you know what code to type.
Where did I find this.
It's not in the Maia's QOL documentation.
This is not an official Maya.
Q Well sanctioned library basically the way that it works is that random developers who teams developers
solo developers go and create these libraries that connect my as well to other languages.
Some of them are more supportive than others.
Like I said some of them are just one person but they usually have their own documentation so the documentation
for this is on get home.
It's good how about com slash my s.
Q LJ s slash my ask.
Well there goes my fridge again.
Very active today.
But if we scroll down you can see well there's a lot of stuff to take a look at but it basically talks
about installing it talks about setting up your connection talks.
Then if you keep going down about once you've established a connection what can you do.
Well here's a very simple query.
We saw something very similar although this is just selecting one.
We did something a little more complicated but if we keep going.
Eventually you'll see we get things about queery which is where we're going just a little bit.
But basically I want to show you there is a source of documentation.
So here we talked about some queries how it works.
We'll come we'll come back to this in a bit but I'm not just pulling this stuff from nowhere and I certainly
don't have it memorized.
I'm not just you know I don't just know how it works.
I'd say the approach is more OK I know what I need to build.
I'm going to be building it with Ruby.
Now let me find the ruby.
My SUV driver or a gem which is what they're called instead of packages in Ruby.
I may find in my ask.
Well Jim Zera connector.
And then you find and then you look through the documentation and you figure out how it works.
OK how do I connect first.
That's the first thing you need to do.
And there's not one syntax.
It varies from language to language.
Somebody made a decision.
So if we go back to our slides here you know somebody made the decision to call this method queery which
I mean it makes sense to call it queery but it could have also been called Make query or perform query
or when creating the connection.
May I ask you all that create connection.
I don't know if someone could have called this this could be database name instead of database but somebody
is making those calls.
And I'm not disagreeing with the way this is named in any way but I'm saying you have to play by the
rules of whoever defined this.
Just like when we're working with my ask you Will we have to use them I ask you all syntax.
There is a specific syntax we have to learn.
Same thing for using these libraries.
So it's not something that comes standard with javascript or with code.
It's something we had to plug in ourselves.
And that means we need to go do the work to figure out how to use it.
OK.
So next up we're going to create our schema.
And it's pretty simple.
All that we need are two fields.
So we'll run create table users will do email and a pretty standard length is 255.
So not that an email is that long but for fields in general textfield people will do Vardar to 5:5 and
we'll make it a primary key.
Why do we want to do that.
Basically we don't want someone to be able to sign up twice with the same email address.
Also it gives us a couple more options for exercises so it's a good thing to do and it's good practice.
This is probably the first time we've seen primary key without autoincrement then we've also got created
out and that's going to be a time stamp.
It could be a date time.
But remember back to that video we did about the difference time stamp is smaller.
It takes up less space and memory and it works just as well except for really far away data in the past.
And in the future 1970 up until when he 38 I think it is is the current range.
We're not going to worry about that because we're dealing with current dates.
You know we're creating a mailing list app or a waitlist app people are setting up now so we don't you
know nobody's entering a date from 650 or something then we're setting the default value to be now so
that when someone signs up it will automatically be filled in as the current time.
But don't forget when we're working with F.A. we are going to insert like 500 users into this table
and we are going to provide a created at a time so that we don't get you know 500 users with the exact
same time.
So we want this default value to be there but we'll also be able to overwrite it manually if we want
to.
OK so let's hop over to cloud 9 and the first thing I'm going to do close this down is just make a new
file.
I'm just going to call it schema data as well.
And the only reason I'm doing that is just to have a record of this.
You could just open up my ask out and start typing.
Create table.
I'm going to do it in here.
Create table users.
OK.
So we wanted email and then we wanted create it at an email is Vardar to 5:5 primary key and created
at is time stamp would work just fine if you left a date time and we want default to be now or we could
also say current time stamp.
OK just like that and we'll save.
We'll hop down to our terminal down here.
I'm in the my ask you well CLIA.
And I'm just going to select database right now and see what we're working with to in the JOIN US database.
So we made a new empty database.
If we look at you know show tables there's nothing here that's correct.
So we're going to create this.
You can either copy and pasted in or you can run the file which I'll do just because it's been a while
source schema data as well.
OK.
Now let's see if it works.
Show tables this time.
Now we have a users table and we can describe it perfect.