Hello, friends, in this video, I shall tell you how to use a CircuLite database in our application.
What is askew like is satellite light, a software larivee, which implementor, which is very easy
to configure.
In fact, there is no configuration required.
It is a self-contained serverless zero configuration.
Database.
Because it is Cervalis Serverless, it can be easily shipped or distributed along with your application.
So a very compact database library is what is this askew like?
Has to like transactions are fully compliant.
What is as it is an acronym for EFORE Atomically.
See, for consistency.
I for isolation
and for durability,
so all these are important prerequisites of a database software, so all the transactions are complying
with these requirements.
That's too light also is very up to date standard, it conforms with the actual 92 standard.
That's cool, is available across platforms, it is available on Unix, Linux, Windows, etc..
As you can be very readily
integrated with Python, because Python distribution comes.
Put with the, if you like, three primordia, so you don't have to import any additional libraries
or packages into the python distribution because it's too late to model is already.
It provides an interface compliant with the DBI API 2.0 Python if if in order to connect any database
to the python you call the interface in between the database and the Python program must be conforming
to the dibby dibby API 2.0 standard.
So it is already, you know, fulfilling that particular requirement.
So this is what Eliscu like is all about how to use the EU lite database in a Python program, first
import vasculitis module, then establish the connection by using the escalatory dot connect function,
the name of the database that you want to create.
Then execute any execute any ESKIL statement can be executed by using the execute function.
So using the connection object, so why not execute inside the bracket?
This is the Ezekial statement here.
What we are doing.
You are using a creative Pascual's query to create tables to run.
These are the different things that are needed.
So when this program is executed, what will happen?
The database DB will be created and inside, which is to run the table will be created.
So such is the way in which there is to like three database can be created using.
Python script.
Now, you have to now interact with that as well as to light database to your application.
So what we have, we will design a form in which the user will enter the data and the data will be posted
to this, you add receipt.
Obviously this you will now be, you know, mapping of it if you function.
The view function is at Odyssey.
Now, this ad RNC function will receive the data from the forum using the Boston method.
So if the matter is paused, then the request, not form attribute of the request object, has all the
data that is sent by the form.
So that will be stored in the python variables, name, address, etc..
All these variables are used to insert the data so far for that.
What we are to do you are to establish the connection.
Obtained the cassette and using the cursor execute the insert operation.
So that is all you can insert their data into the underlying table, which is in the database.
So now that you have entered the data into the lunch table using the ad I receive, you function now
suppose that the student's table has a few records and you want to display the records in the school
lunch table on the client's browser by a certain view function.
So I am defining a route list which is mapped to a function list.
So when this list you are telling is accessed, this list function will be executed and then what will
happen?
You have to establish the connection, obtain the cursor and execute the select query, select start
from students.
It will extract all the records and it will be stored in a ResultSet object called rules.
So this is a multi dictionary object, which because each row is itself a dictionary, the key, the
filename value filename value.
A number of weeks are there and then there will be no such records.
So therefore it will be, as I said it, in the multi dictionary object.
So that multi dictionary object is given as a parameter to this render template function, which will
render the estimated page list estimate inside this list that estimate there will be a ginger to template
called.
Which will take one role at a time from these rows object and all of these rules, there are two, you
know, fields, the subject name and the value subject name and the value.
So the name of the field and associated with the value of it will be displayed in a table.
So as a result of this, you will get a table displayed on your browser, which will be equivalent to
the records that are present in your surance.
So there are different activities involved.
One is a form, a stable form.
Second is the insert activity done by the Python script.
Third is the list activity and fourth is the list, not a simple template to be rendered.
So all these activities now I will show you with the help of a comprehensive example which will which
will cover all these activities put together.
So how to use and has cue light database as a back into your flask application that we want to see with
the help of this demonstration and example.
So.
Database, not TV.
Escalade database named as database Nadhim is already.
Present in the flask applications folder, and there is inside this database, the DVD table called
Students and the structure of the students table is that there are such for fields name, address and
pin code.
OK, and now this.
The contents of this database, NDB, I am sure, with the help of a software called the Escalade Studio.
So this is the structure of this table and presently these five records are already present in it.
This is hilarious to you, is a front end for many, manipulating and managing the light tables.
You can create a table at the data, run different queries and so on.
But then but then that is not our intention to use as I'm just using these vasculitis to do to show
the effect of the Python application, uh, in the database.
What what happens now when we run and as Kilgariff for insert a record will come back to this studio
and see whether that insertion is properly done or not.
And then when we select query on the.
On this database, through our application, we will verify whether the same records that are seen here
will be displayed on our browser or not.
So that is the purpose of Escalades through your using here.
OK, so we are interested in the still unstable, this is the structure and these are the records at
this point of time in this.
Now, the Python code.
For performing or manipulating the database.
That code is written in this Randhawa.
Python's standard distribution already comes with a escalatory module, so you don't have to additionally
install any other module in order to use, as you like, database as a backend to your Python program.
So all you really just import this is you like three.
Into your application, of course, you will have to import all these prerequisites, the flask class,
the render template function and the request object.
Now in this.
Quarter in this program or in this Python script?
There is one you are in.
That is defined is backslash.
So that means localhost 5000, backslash this backslash, Eurail is.
Matter to the view function called home and what it is doing, it is just rendering, uh, a home stable
template.
So you have to say return render template home rowdiest.
So what is there in just a minute kind of thing, which will have to hyperlinks want to add when you
click that and record the activity of adding a record will start and the other is list.
So let us have a look at this before proceeding.
So this is the estimate called.
For this home road in which.
Nothing, but there are two, you know, hyperlinks, one hyperlink to the statement or sentence, add
a new record to which a slash and a new.
You know, you are Liz hyperlinked.
And the other is sure list it is hyperlink to another e-mail list.
So obviously these two your are defined in your relative pattern.
But then as far as this Ormerod e-mail is concerned, when this is rendered, you will see Aminul below,
which you will see two hyperlinks, one taking you to our new record.
Other technologies to show list find.
So let us come back to the button called.
This is one you are all that is defined.
The other is, as we just saw, enter new.
So when the user clicks that add new record hyperlink, he will come here.
Right, and this you are in.
He's attached or mapper with this view function, new student.
So what will happen, another template which is present in the template folder of your application called
Student Body, and that will be rendered.
So obviously, we have to have a look at student bodies.
Well, what is that?
You contents of that student e-mail.
Well, this is the slenderest e-mail, it is.
Nothing but a farm is clear.
In the form there are the different form elements are one is able to be able to text for name, address,
address, addresses provided and text area.
Then city in whatever you want to name, is equal to city and a been called in name equal to PIN and
the Apple type is equal to texture.
So there are essentially four text boxes and then there is a submit button.
Those are all the former in.
The fall.
Importantly, the farm attributes are here, mental attributes to post.
And the action attributed to the oil for AD.
At record, at Oddisee function, which is there in the Python pool.
What is the URL for this er odyssey that will be.
Taken up as the action attitude of this former.
OK, so when the user clicks the original record link, he will be presented a form to fill the data
and submit the submit will take you to this view function at record or ad odyssey as it is written there.
So come back to the Python code and see what is there and see.
This is that you are ill defined with the help of this fruit decorator slash ah ad Oddisee meters post
and get.
So if the form has been posted.
Then what will happen, the request form object?
What is it?
It was not formal.
It is essentially a dictionary of.
The former living dead and its associated values, associated value will be stored in the variable ADR
city and PIN requestor form and will.
Fisher, the name at the city, had been good, thanks so all the farm data is now coming into your
bite on wall.
Now, then.
Establish the connection with the database that we are using, a skilled connect function will establish
the connection.
Is using this connection object or turn the cursor so she will not cursor will open the cursor object
and using this cursor?
Execute the obscure command, what is going on, do you want to execute essentially this data is to
be inserted so the query will be answered insert into students.
These are the this is the full list, name, address, city pin code and the values to.
The story in those respective fields are these variables name, address, city and PIN code.
So this is the query to be executed that will be executed.
If it is successful, then.
The.
The result will be committed and it will generate or it will create a variable CalEnergy messages to
record successfully Arijit if at all, it happens to be the case that there is a certain error to account
for that error.
All this is put into a trial block.
So in case of error, the exit block will.
Takeover, you don't want anything untoward to happen in your retirement, so therefore you have to
roll it back.
And messages of error in your search operation will be the message.
So in the event of successfully insert a security message will be recalled, successfully added, otherwise,
it will be a routine insert operation.
In any case, you have to.
Display these messages on the result, not e-mail, so the template is a large achievement, along with
an attribute or parameter meji.
So that image will be flashed on this result.
So what is that?
That, of course, then we have to, uh, you know, look for Result-oriented and what is there in is
a lot.
OK, so this is one function, just aminul this is another function which will which will, uh.
You know, opening from.
When the form is posted, the search operation will be either perform or not perform in both cases.
This finally block will render this result.
No result or XHTML will just.
Flashed this message, Mawji, a result of an insert operation will be the value of this M.G. variable,
either it will be a success or a failure message and then followed by that to give a hyperlink to go
back to the home page.
So that will take me to this.
Because you are in.
Right.
This is the result, that estimate.
And finally, there is a specialist you are, which is defined and it is map to a room function called
list.
So what you have to do, you are to extract all the records that are currently present in the student's
table, and that can be done by a skilled clerical select.
So select start from students.
Is the query to be executed?
To obtain the cursed object and cursed out execute.
The result of this castle not executed will be a ResultSet, which will sold in the rose variable.
Taking these roads.
As a variable or as an attribute to this render template function, this list, not esteemable, will
be rendered.
OK, so.
Obviously, what is there in the list?
Well, this is the final piece of code which is required for this particular based application that
is not a stimulus.
Again, it is a table, as you can see.
It is a table.
First part of the table is to render the headers all the filenames, name, address and pin code are
used as the first row of the table.
And for the actual records, which will be stored anywhere in the.
Multitiered object called rules, so lub orit put the loop in a danger to template syntax for each rule
in rules, what you do rule, name, rule, address, Rosatti ropin all these.
These are the names and raw name, will you the value of.
The name Phil in the first row.
This will be the first row.
Next iteration of the world will take will take place, it will take the second or third row for through
and so on, and each of these elements will be stored in a.
They will rule.
So this is the first rule is the header, all the field names will be displayed at the first row and
the subsequent rules will contain the data from all the records in the student stable.
OK, so this is the app.
This is the effect of Liselotte estimate at the end of the table again.
A hyperlink to go back to the main hall, go back to the home pages provided so you can go back to the
mainland if you want, you can add a new record are listed again.
So these are all the different pieces, of course, some e-mail templates.
The you are defined in your Python application associated with functions.
Everything is in front of you now we.
Execute this and see what.
Is the result.
So our Python Flask application is written in Randhawa, so execute that.
The server will start.
Now they have to go to the browser and give the yareli, which will open up the menu, so in the browser,
just enter localhost 5000, which takes you to.
The home will function.
It gives you a menu with two hyperlinks and new record and short list.
So first I will click the short list link and you should be able to see the records that are presently
available in the student's table of your.
Escolar table.
So these are the records you can verify the presence of these records.
By going to the studio and verifying that these records are there, there are five records.
So just go back to the rescuers, to your screen and verify it, so as you can see, the student stable
contains all these records that are displayed on your brother's page.
OK, so the list operation is.
Working perfectly.
Now, let me go back to the home page by clicking on this.
And click on our new record, What Happens Soudan, that e-mail will be rendered, it will be a form
in which you can enter the data.
That's it.
So some that are a little.
For instance, if I say.
Something like this.
And the subsequent submit button will take you to enter new.
You are in the associated view function, will execute the insert query and add the recording to the
table, so the result of insert operation is recorded successfully added.
I will go back to the homepage and now I will list.
So this is the latest record that has been added.
If I go to the studio there also, I should be able to.
Find that record there.
So this is the student stable and the data in which, if you find the sixth row has been added.
This is the record that has been recently added.
So our.
Insertion and operation.
Done with the help of insert, query and select query that can be easily done with the help of your
application on this killer database.
So this is the complete demonstration of.
Using escalate along with your flask application.