A Repository Based on PostgreSQL

Let’s learn about the vital role of PostgreSQL in a Python application.

We'll cover the following

Overview

Let’s start with a repository based on the popular SQL database PostgreSQL. It can be accessed from Python in many ways, but one of the best ways is through the SQLAlchemy interface. SQLAlchemy is an ORMA package that maps objects (as in object-oriented) to a relational database.s and can normally be found in a web framework such as Django. It can also be found in stand-alone packages, such as in our case.

Learning about ORMs

The important thing about ORMsA package that maps objects (as in object-oriented) to a relational database.is that they’re very good examples of something we shouldn’t try to mock. If we properly mock the SQLAlchemy structures used when we query the database, then the code will become very complex. This isn’t easy to write and maintain. This is because every single change in a query (or queries) results in the need to write another series of mocks.

Get hands-on with 1400+ tech skills courses.