No video

FastAPI & SQLModel - Database Interaction in FastAPI apps with SQLModel

  Рет қаралды 7,019

BugBytes

BugBytes

Күн бұрын

In this video, we refactor the Pydantic models from the previous video into SQLModel classes that can interact with our database and define the schema of our tables.
We'll see how to re-write our FastAPI handler functions to use this database.
▶️ Playlist: • FastAPI - Complete Cou...
☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
ko-fi.com/bugb...
📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
00:35 SQLModel intro
05:18 Create relationships between SQLModel classes
08:18 Creating database connection
13:04 Using database in FastAPI handler functions
▶️ Full Playlist:
• FastAPI - Complete Cou...
𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: bugbytes.io/po...
👾 Github: github.com/bug...
🐦 Twitter: / bugbytesio
📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
SQLModel: sqlmodel.tiang...
FastAPI Lifespan Event: fastapi.tiango...
#python #fastapi #webdevelopment

Пікірлер: 41
@LaichuTV
@LaichuTV 6 күн бұрын
Bro thank you for creating these videos, deeply respect!
@bugbytes3923
@bugbytes3923 3 күн бұрын
Thanks a lot for the comments bro, cheers!
@dixon1e
@dixon1e 3 ай бұрын
This is incredibly well produced and deeply informative. Thank you.
@bugbytes3923
@bugbytes3923 3 ай бұрын
Thanks a lot, delighted to hear that! Cheers!
@opticonor
@opticonor 4 ай бұрын
Lots of value in this video, thanks!!
@bugbytes3923
@bugbytes3923 4 ай бұрын
Thanks a lot!
@thierryyolepiot9951
@thierryyolepiot9951 2 ай бұрын
Can you show hoz to set up FastAPI with MySQL and PostGreSQL (especially with the async features)?
@djtoon8412
@djtoon8412 2 ай бұрын
also setting up with postgres docker and traefik .Also an additional content can be sending emails and show how to create email templates
@boholsurf_2749
@boholsurf_2749 23 күн бұрын
great video
@bugbytes3923
@bugbytes3923 21 күн бұрын
Thanks a lot!
@juvewan
@juvewan 4 ай бұрын
Endpoint functions are defined as `async def`, but the db operations inside are all sync, including the get_session depency. This is bad in a real project. async def endpoints are running in an event loop, time cosuming db operations are not awaited, so they will block the event loop.
@zoxxar
@zoxxar 4 ай бұрын
can you give an example of changing a DB operation to support async?
@kushalpy
@kushalpy 4 ай бұрын
Love from Nepal❤
@bugbytes3923
@bugbytes3923 4 ай бұрын
Thanks a lot!
@Steve51791
@Steve51791 Ай бұрын
Why should one create subclasses and inherit from a base class? Is there a reason you shouldn't just, for example, put the primary key field in the parent class?
@catchychazz
@catchychazz 4 ай бұрын
Is SQLModel still necessary with SQLAlchemy 2.0?
@tascsolutions6483
@tascsolutions6483 3 ай бұрын
Great content! Can you please explain why some tutorials use pydantic models(schemas) AND sql models (models)? I find this confusing and causing issues.
@matis9783
@matis9783 3 ай бұрын
Maybe single responsibility principle
@TOn-fx2gr
@TOn-fx2gr 2 ай бұрын
That's how it worked in the paste but then the developer of fastapi created sqlmodel which use pydantic and sqlalchemy under the hood to make our life much easier ,i think most people in youtube are not aware that sqlmodel exist
@ayushshende4290
@ayushshende4290 3 ай бұрын
A video on env config and file structure for bigger projects would also be helpful
@recaseng
@recaseng 3 ай бұрын
Please do more on the crud operations as well as error handlings please
@farzadmf
@farzadmf 4 ай бұрын
Instead of converting the type to a string, you can do `from __future__ import annotations`
@AmoahDevLabs
@AmoahDevLabs 4 ай бұрын
great one.
@bugbytes3923
@bugbytes3923 4 ай бұрын
Thanks as always!
@adhd_arti
@adhd_arti 4 ай бұрын
Best content!
@bugbytes3923
@bugbytes3923 4 ай бұрын
Thanks a lot!
@djtoon8412
@djtoon8412 4 ай бұрын
can we also get one for microservices using gRPC
@gerrior
@gerrior 2 ай бұрын
Timestamp: 18:30. Even after adding `None` to the `band_id` at runtime I'm getting "pydantic_core: 1 validation error for AlbumBase" "band_id missing". I am using Progres instead of SQLite.
@fernandohtr
@fernandohtr 2 ай бұрын
I also had a problem around this video time. The error returned was not so clear. To solve the problem in my case, I had to transform the "album.release_date" from string to datetime.date. It was something more or less like this: if band_data.albums: for album in band_data.albums: raw_album_date = album.release_date.split("-") year = int(raw_album_date[0]) month = int(raw_album_date[1]) day = int(raw_album_date[2]) album_date = date(year, month, day) album_obj = Album( title=album.title, release_date=album_date, band=band ) session.add(album_obj)
@Ceddybaer
@Ceddybaer 2 ай бұрын
I ran into the same issue on SQLite. I fixed it by adding "default=None" to the parameters of Field().
@thierryyolepiot9951
@thierryyolepiot9951 2 ай бұрын
@@Ceddybaer I added "default=None" to the parameters of Field() on line 23, ie band_id: int | None = Field(default=None, foreign_key="band.id") But the error still remains
@subz424
@subz424 28 күн бұрын
@@Ceddybaer Nice! I like this solution, thank you 😃.
@beefbox
@beefbox 4 ай бұрын
Hey, do you consider making an unpoly video? I feel like the library is so underrated.
@bugbytes3923
@bugbytes3923 4 ай бұрын
It has been on the list for a while, yeah. I'll try and get that done soon.
@fazlehadiazmat7g803
@fazlehadiazmat7g803 Ай бұрын
dyed your hair?
@alexandrodisla6285
@alexandrodisla6285 4 ай бұрын
restAPI,sqlmodel,alembic. docker .compose and metrics
@bugbytes3923
@bugbytes3923 4 ай бұрын
Alembic + FastAPI + SQLModel early this week! Thanks.
FastAPI & Alembic - Database Migrations in FastAPI apps
18:33
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,8 МЛН
Fortunately, Ultraman protects me  #shorts #ultraman #ultramantiga #liveaction
00:10
Parenting hacks and gadgets against mosquitoes 🦟👶
00:21
Let's GLOW!
Рет қаралды 11 МЛН
SQLAlchemy: The BEST SQL Database Library in Python
16:39
ArjanCodes
Рет қаралды 62 М.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 261 М.
FastAPI, Flask or Django - Which Should You Use?
9:49
Tech With Tim
Рет қаралды 67 М.
Modern Python logging
21:32
mCoding
Рет қаралды 175 М.
НЫСАНА КОНЦЕРТ 2024
2:26:34
Нысана театры
Рет қаралды 1,8 МЛН