Databases With SQLModel (Connection, Lifespan Events, And Models) - FastAPI Beyond CRUD (Part 5)

Опубликовано: 09 Март 2025
на канале: Ssali Jonathan
5,211
134

In this video, we connect our application to a PostgreSQL database using SQLModel as well as an async DB API (Asyncpg). We look at different concepts involved like creating a database model, choosing when to connect to that database, and so on. We look at FastAPI lifespan events that can help us set up the database connection at the start of the application.
#fastapi #sqlmodel #python #apidevelopment


SOURCE CODE:
https://github.com/jod35/fastapi-beyo...

COURSE WEBSITE:
https://jod35.github.io/fastapi-beyon...

PLEASE DONATE TO THE CHANNEL THROUGH:
BUY ME A COFFEE:
https://buymeacoffee.com/jod35

PATREON:
  / jod35  

You can also consider Becoming a member of this channel.

FOLLOW ME:

X:
https://x.com/jod35_

GITHUB:
http://github.com/jod35

Timestamps:
(00:00:00) Introduction
(00:04:05) Creating a database
(00:05:59) Environment variables with Pydantic Settings
(00:15:10) Create the engine object
(00:20:20) Lifespan events
(00:26:40) Connect to database using lifespan event
(00:31:42) Create a database model
(00:43:17) Create models in database
(00:47:34) Confirm tables in database
(00:48:49) Conclusion