Using SQLAlchemy Asynchronously With AsyncIO (SQLAlchemy 2.0)

preview_player
Показать описание
In this video, we look at how we can use SQLAlchemy (both the core and the ORM) with asyncio in Python. This gives us the ability to make use of Python asynchronous features. It also allows us to use SQLAlchemy with asynchronous Python frameworks like Tornado or FastAPI.

#python #sqlalchemy #python3

SOURCE CODE:

PLEASE BUY ME A COFFEE:

SUBSCRIBE:

GITHUB:

TWITTER:

TIMESTAMPS:
(00:00) Introduction
(01:35) Project dependencies
(03:29) Connecting to the database (core)
(08:57) Running synchronous functions
(10:05) Inserting data (using the core)
(13:42) Select statements (using the core)
(18:29) Closing a connection
(20:08) Creating a connection (using the ORM)
(23:48) Creating an async engine
(26:00) Creating database tables
(27:49) Inserting data (using the ORM)
(36:05) select, insert, delete
(45:50) Conclusion
Рекомендации по теме
Комментарии
Автор

I think this video was requested a lot. I hope you enjoy it. Thanks for watching.

SsaliJonathan
Автор

I like your all SQLAlchemy teaching! Very good a series talk.

liuyan
Автор

Exactly what I needed to figure out my issue in fastapi sqlalchemy and asyncio. Good Job.

theroycefamily
Автор

Excellent video!

I especially appreciated two things:

1. Comparison of the old style connection oriented usage of SQLAlchemy with the newer ORM session oriented methods.

2. The contrasting of examples (the right way to do it) with counter examples (wrong way to do it).

You frequently apologized for your "mistakes". Maybe they were mistakes, or maybe they were part of your lesson plan. In either case, keep up the the good work!

The example/counter-example method is a highly effective teaching method in training humans, rats, pigeons, large language models, and just about any being that learns.

Showing the examples shows the "happy path", while showing the counter-examples shows the boundaries of the path. And showing how to fix the errors shows how to find the center of the happy path again. Too many videos only show the "happy path", leaving it to the learner to figure out what went wrong when they strayed, and to figure out how to get back. At least in the cases in which you showed the contrast, your learners will have some clue when it happens to them. Oh yeh, I have made every one of the mistakes you illustrated.

I have been a programmer since 1982. I have experience with many languages. I have been using Python more or less full time for around four years.

Still, I learned from you video.

Thank you.

Tom

tomdonaldson
Автор

We don't have to use `await session.commit()` at the end of insert method because when we use session.begin(), it makes sure session is commited before exiting context manger. At 34:55, you can see there are two COMMITs at the end!

HarshVerma-xsux
Автор

Hey, thank you for this video. But I have a question about dispose() method.
As written in sqlalchemy docs, it's advisable to dispose connection when we are with the engine. In your example it's pretty simple because we are running all the code inside main method, but in real life I can use class with the field that contains async_engine. So the question is when should I dispose() this engine? Because I don't know how my class will be used and when I can dispose() the engine...
Hope it makes sense

filipplando
Автор

I really like your content bro.. May i request flask with react js..

Love from indonesia

peabc
Автор

hi, i am using sqlalchemy in my project, but while executing the query it got hanged, while running server

in my project, i am using scheduler in python.

Thanks in advance.

anupojujaswanth
Автор

How about a Sqlalchemy orm with data classes video?

chriskeo