Creating an SQLAlchemy DB instance
SQLAlchemy is a Python SQL toolkit and provides ORM, which combines the flexibility and power of SQL with the feel of Python’s object-oriented nature. In this recipe, we will understand how to create an SQLAlchemy database instance that can be used to perform any database operation that shall be covered in future recipes.
Getting ready
Flask-SQLAlchemy is the extension that provides the SQLAlchemy interface for Flask. This extension can simply be installed by using pip
as follows:
$ pip install flask-sqlalchemy
The first thing to keep in mind with Flask-SQLAlchemy is the application configuration parameter, which tells SQLAlchemy about the location of the database to be used:
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ('DATABASE_URI')
SQLALCHEMY_DATABASE_URI
is a combination of the database protocol, any authentication needed, and also the name of the database. In the case of SQLite,...