Chapter 6: Databases and Asynchronous ORMs
The main goal of a REST API is, of course, to read and write data. So far, we've solely worked with the tools given by Python and FastAPI, allowing us to build reliable endpoints to process and answer requests. However, we haven't been able to effectively retrieve and persist that information: we missed a database.
The goal of this chapter is to show you how you can interact with different types of databases and related libraries inside FastAPI. It's worth noting that FastAPI is completely agnostic regarding databases: you can use any system you want and it's your responsibility to integrate it. This is why we'll review three different approaches to integrate a database, that is, using basic SQL queries, using Object-Relational Mapping (ORM), and, finally, using a NoSQL database.
In this chapter, we're going to cover the following main topics:
- An overview of relational and NoSQL databases
- Communicating...