Building APIs with FastAPI · 12-day planAll days
Day 7 of 12 35 minSQLModelSessionsQueries
Store data in a real SQL database. Define SQLModel classes that are both Pydantic models and database tables, create the engine and tables, open a session per request with a dependency, and build the CRUD API on top of SQL queries with filters, ordering and relationships.
By the end of today you can
- Define database tables with SQLModel
- Create an engine and the tables, and open a session per request
- Insert, query, update and delete rows with a session
- Filter, order and paginate with select()
- Keep separate table, create, update and public models
What's inside
- 5 sections
- 2 diagrams and mind maps
- 3 code examples you can run
- 5-question quiz
- 1Tables and sessions
- 2A database-backed API
- 3Safe from SQL injection
- 4Related tables
- 5Going further
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free