Okay.
Let's continue.
So if you remember we are working in the A building.
We are building the back end of our basic, uh, level three application.
And what we have done so far is the initial setup.
We have created the virtual environment, we have installed the necessary packages, and then we have
created the database, entered the credentials of the database in the dot m file and validate the data
types of the uh, the credentials with pedantic.
We are now going to create the table we are going to use in the database.
So if you are not familiar with databases, um, don't worry about uh, about the concept of a database
is it cannot be more simple.
A database is just a collection of tables.
And you already know a table because you have worked with spreadsheets and tables of columns and rows.
So.
So a database is just one table or a series of tables, you know.
So in this case we are going to do the most simple type of a database, which is one database with just
one table.
Okay.
So we already created the database.
You remember when we did this.
And we call the database my database in a very original manner.
And now we are going to create the the table okay.
So before that we check the local server.
And uh right now well here we are providing you alternative ways to check the the server.
Don't worry about this.
Uh, now you can try this later.
You know, these different approaches etc..
So now.
After the initial check.
Now close the app and set the database migrations.
When we say database migration is okay, we are going to create a table.
Okay?
So in order to close the backend server you have to use control C okay.
So you press the key control and the key C at the same time control C boom.
And you will see that in the terminal the server stops okay.
So now we are going to write a some lines that are going to sound like Chinese to you.
Don't worry.
The main purpose of all these lines is to create a table.
Okay.
So we are going to use a package called Alembic.
And here you have a detailed explanation of what Alembic does, what this, uh, instruction does,
etc. but right now I'm not going to stop there.
We are just going back to our code editor.
And when you when you, uh, execute this in your terminal, the application is going to create this
folder for you, the Alembic folder.
And you as you can see, this is just a version control a device to check.
You know what we are doing with our database okay.
So you will see what happens here later.
So.
A the first thing we are going to do is we are going to introduce this little, uh, change in the M
file MP file that Alembic has created for us here.
So in order for, uh, Alembic to use the credentials of the database, we are going to, uh, include.
These line, these config set.
What we are telling here is telling okay.
So you are going to use and the the database.
We have a with this database user and database password.
So we are telling it in order to know what are the credentials of the database, you will have to go
to the main m file okay.
So for Alembic to know where is this m file we are going to enter here import OS.
And then from dot m import load dot m which is what we are telling you here.
And load them.
So this line, this line, this line and this line, the 18 line, which is very long as you can see,
are the ones that we are telling you that you have to add to the default m dot pi that Alembic has created
inside of the Alembic a folder.
Not important.
This is not important.
Okay.
And so just, uh, stay with me and get the concept, and that's it.
So now we are going to create the table of our database, and we are going to call this table todos.
Okay.
So in order to create a table in the database called todos you enter this command in your terminal okay.
And you will see after doing that you do these operations.
My recommendation is that first you pay attention to the video.
Second, you download the code from GitHub.
Third, you a repeat these operations with a copy and paste.
So you open a new folder and you start copying and pasting, you know, and the things in this exact
order.
Whenever you find a problem, a doubt, a question, you go to chat, GPT four and the different sources
you have, okay.
And you do that the times you need in order to get familiar with the main concepts.
So when you create a table, you will see that in Alembic versions you are going to have a file like
this one.
That is just a way to acknowledge that you have created the table.
And in this, uh, file we are going to introduce a few changes which are basically these lines here.
Okay.
It's just telling, uh, that what are the contents we are going to have in the table.
So in this case, our table, each of the items, each of the tasks is going to have a name.
It's going to have an ID and it's going to have a completed A.
Element.
Right?
So the computer is going to be what we call a boolean.
So a complete it can be true or false okay.
So not very important.
We are just configuring the database okay.
So in order to uh execute it uh the migration is just a way to like okay.
Yes.
You have created the database and the table.
Excellent.
So in order to execute this we are going to open Postgres from uh, the terminal.
We are going to open our database inside of Postgres.
So this is like opening Postgres in your in your computer and opening this database in progress in Postgres.
And then you are going to create a database user with this name.
And with this password you can choose the name and the password you want.
This is the ones we are using in this example.
And you are going to tell Postgres that this user has has all privilege so it can do whatever it wants
okay.
So we are telling here, give the user with this name user 12 all privilege.
So all all the permissions in order to do whatever he wants to do in the database, name my database
okay.
And then this is going to close Postgres in your terminal okay.
Here you have an alternative way of doing this.
But don't worry about that.
Then you go to Alembic dot.
Ini.
Okay, alembic ini and you edit the line.
64.
Okay.
This line you are going to edit with your username, your password and the name of your database.
And in this case a we know this is a local database okay.
So you are also going to edit the the main dot m file.
Uh, in order to include your right user and right password.
Okay.
So now we have a the new table in our database.
And in order to.
Close the deal.
We are going to run this, uh, command in terminal.
Okay.
Alembic, upgrade head boom.
That's it.
Then if you want to check the status of your data database in your terminal, you do this.
What this is doing is like, okay, open this database and show me everything that is in the table called
todos.
Okay.
That's it.
And then quit close.
Okay.
Not important.
We give you some some more details about that here.
We are also telling you that there is another file called database.py that has the object relational
mapping, which is more additional information to uh let the application know about the, the the database
and how to use the database, etc., etc..
Not important.
Now.
Models.py more the same.
Uh, we are just, you know, configuring our database or go here in detail later.
Now it's not important.
What is important now is the most important file of the backend, uh, application, which is this Crud.
In this Crud, we are going to write the Python functions to, uh, perform the main operations of our
application.
Okay.
So here we are going to explain you in super detail everything that you see here.
Okay.
So every little piece of this code is super explained in this notebook okay.
Super explain.
Okay.
Then we are explaining you the things you are going to do in the router.
So the router is what is going to convert our Python application in a web application.
Because the router manages the routes, the routes of the web applications, the different pages and
the different actions.
Okay.
So all this code you have here is explained in detail in the notebook okay.
So once you create the to DOS router, you will need to come back to the main file and uncomment this
line and this line.
Right now they are uncommented.
They are okay.
But before I told you to enter here a pound sign and the same here.
Okay, now we have the router so we can clear the pound sign there and there okay.
Then you can run the server again from the terminal with the same, uh, instruction.
And you can you don't have a front end.
So you cannot.
Without a front end, the user cannot enter a task here or delete a task or update a task, but you
from the back end using the terminal can perform this operation.
So here you have how to try your graph application from your terminal.
So this is what you need to write to create one.
To do tasks from your terminal and to display, to update, to delete, etc., etc..
Okay, so right now you have a very basic back end of a Crud application.
I know a lot of new things.
Uh, here.
Uh, do not feel overwhelmed.
Just stay with me.
Bear with me.
Keep the main concepts and start repeating this subsection in the way I have recommended until you start
feeling comfortable.
Whenever you have a problem, whenever you have a question, whenever you have an error, while you
are repeating this exercise, go to chat.
GPT four and the other sources we have recommended.
Okay, so download the code from GitHub.
First, repeat the process once in your computer and then twice and third time, etc. etc. don't bother.
Don't don't worry about creating many, uh, different folders for many different applications.
Uh, just repeat this until you feel comfortable and whenever you find a problem, just investigate
about it, okay?
And once you feel a comfortable, then we go to create the front end of our application.
Okay.
It will be in the notebook.
It will be what we call the part two, which is here.
Okay.
So in the next subsection we are going to create the front end of the application.