fastapi-mvc
fastapi-mvc copied to clipboard
[Databases support] Implement Session class responsible for managing SQLAlchemy session
- [x] I have searched the issues of this repo and believe that this is not a duplicate.
Feature Request
This class will be responsible for managing SQLAlchemy engine connection and session.
To figure out/clarify:
- What SQLAlchemy engine and session/sessionmaker parameters should be configurable for the user via pydantic
BaseSettings
configuration class. - How long keep an open session? Perpetual per worker? Or per request with a context manager?
- Only implement async session or sync as well?
- How to pass session to FastAPI controllers? Via FastAPI
Depends()
? Or just do plain import and access class variable forsessionmaker
object instance? - How to handle different database engine hacks (for instance sqlite needs
connect_args={"check_same_thread": False}
). Might be useful: https://github.com/pallets-eco/flask-sqlalchemy/blob/e5bf821072de0d55ff92891432004322864a7265/src/flask_sqlalchemy/init.py#L888 - ?