Defining our data access layer
Now we have an application that takes in a number and calculates a Fibonacci number based on it. However, a database lookup is quicker than a calculation. We will use this fact to optimize our application by initially performing a database lookup when a number is submitted. If it is not there, we calculate the number, store it in the database, and then return it to the user. Before we start building, we will have to install the following packages using pip
:
pyml
: This package helps in loading parameters for our application from a.yml
file.sqlalchemy
: This package enables our application to map Python objects to databases for storing and querying.alembic
: This package helps in tracking and applying changes to the database from the application.psycopg2-binary
: This is the binary that will enable our application to connect to the database.
Now that we have installed all that we need, we can enable our application to store...