Add SQLAlchemyAdd SQLAlchemy

In this chapter we are going to go over databases. Flask does not actually come with a database included with it when you downloaded the framework because they want to keep it lightweight. So, if you want a database then we have to actually use an external third-party extention.

We will use one little library has interoperability with Flask called SQLAlchemy that has interface to interact with DB like SQLite, MySQL or PostgreSQL. Let’s just get into it and I’ll show you how it works.

  • Go down into your terminal and just run:
  • Then need to import new library into your main applictional file main.py
  • Start setting up our database. The first thing, we are going to do is tell our Flask application where the database is going to be stored.

In development mode is easy to use SQLite database. SQLite stores database locally as a file. But in production mode you can use different database if you want. The nice thing about SQLAlchemy is that it allows us to use any database we like and it is simple just changing the route to different database. And all the query to the different databases is the same.

Everything was clear?

Section 2. Chapter 2