How to use SQL Alchemy models the same way than django models
I have been using fast api for a few days and passing the db
session around is starting to bother me a bit. In my previous project I was using a django backend, where to make queries I only needed to import the model. Something like:
from models import SomeModel
class SomeRepository:
def method(self):
SomeModel.objects.filter(...)
But in fast api, I need to take care of the db
session object and pass it as argument, something like:
from sqlalchemy.orm import Session
from models import SomeModel
class SomeRepository:
def method(self, db: Session):
db.query(SomeModel).all()
Is there any way to make fast api and sql alchemy work like the way models work in Django?