Open acidjunk opened 4 years ago
FWIW: For now I'm using the https://github.com/absent1706/sqlalchemy-mixins which seems to work OK. After including the middleware in main.py I inject the functionality like this:
with db():
# Enable all sqlalchemy mixin (like query support)
BaseModel.set_session(db.session)
Whilst the Base model stuff looks like this:
Base = declarative_base()
class BaseModel(Base, SessionMixin):
__abstract__ = True
pass
@acidjunk Hi, thanks for the input. Does sqlalchemy-mixins work with async? specifically, using https://github.com/encode/databases
I don't know: probably not (yet)
Async stuff is alpha level: https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html
in the end we wrote our own sqlalchemy bindings; and we didn't use this library as it had to much boilerplate for managing connections. We also needed an easy way to run pytests tests with migrations applied to DB.
https://github.com/workfloworchestrator/orchestrator-core/blob/main/orchestrator/db/database.py
@mfreeborn @conradogarciaberrotaran any updates on this issue? It would be very useful to have.
Whilst transitioning our stack to FastAPI I luckily found this package. Thanks for the work on this package; it's a nice and easy way to get a DB connection without the need for a dependency that injects it in all controllers.
Our old Flask project uses some functionality from flask-sqlalchemy, that seems absent in fastapi-sqlalchemy: a query property on all models. So instead of
db.session.query(User).all()
we are usingUser.query.all()
Are there any plans to support this kind of querying?