Skip to content

Introduction

In this section, and early in the project, we'll introduce working with a database. Of course, it is possible during development to use hardcoded dictionaries, but this is a pragmatic guide.

The creator of FastAPI also has an accompanying project called SQLModel, which is an elegant approach to working with SQLAlchemy for hooking up models in your code and creating database tables in a database.

In reality, the database tables you create shape the application. So, as we go on, we'll configure the project with either SQLite or PostgreSQL, add some SQL models and use Alembic for applying database migrations.

Tip

When you think about it, just about every web application you can imagine can be boiled down to four essential functions, Create, Read, Update and Delete. And, to persist the creating, updating and deleting of records, a database is needed.