tortoise-orm
tortoise-orm copied to clipboard
Enhancement for FastAPI lifespan support (#1371)
- Add a new class
RegisterTortoise
which can be used in lifespan context - Enhancement
register_tortoise
to auto run in lifespan context, but echo deprecated warning
Description
Support register in fastapi's lifespan and leave register_tortoise
there to compare old version
Motivation and Context
For some running projects, people may want to only upgrade dependencies without changing any code.
While for new project, it is more flexibility to use async with
format to register db.
How Has This Been Tested?
make test
cd examples/fastapi && PYTHONPATH=. pytest _tests.py
Checklist:
- [x] My code follows the code style of this project.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] I have added the changelog accordingly.
- [x] I have read the CONTRIBUTING document.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.