Closed Mdslino closed 4 years ago
What does crud.login.get_by_email()
do? The point of this library is not to magically convert sync code to async. If this code is blocking, it will still be blocking after you wrap with with async_()
.
It's just a database query with SQLAlchemy Session on it.
def get_by_email(self, db: Session, email: str) -> Optional[User]:
return db.query(self.model).filter_by(email=email).first()
Right, so this does not give you any benefit, you are still blocking. Not sure why your timings say otherwise, but this project isn't designed to help in your case. You shouldn't be using SQLAlchemy in an asynchronous application.
So what is the correct application scenario for this project
The goal is to allow regular and async functions to call each other. There is nothing that makes blocking code non-blocking, at least nothing at this time.
Use cases:
I did a little test with a application i have written in FastAPI using SQLAlchemy as ORM and the results are amazing:
The route code is the following:
Login Sync Duration: 0.015734 Login Async Duration: 0.002904
The results are outstanding
Really thanks for this. I'll test more later this week.