this repo based on teamhide's fastapi-boilerplate
pip install cookiecuttercookiecutter https://github.com/rapidrabbit76/Fastapi-Boilerplate.git [--checkout branch: is option]- cookicutter
- cache-control middleware
- cache
- containerize
- middleware logging
- SQLAlchemy Multiple database
- starlette-admin
TODO
cache depends on aiocache
check core/db/session.py and core/settings/settings.py
- set
DB_AUTH_DB_URL
engines = {
"writer": create_async_engine(
env.DB_WRITER_DB_URL,
pool_recycle=env.DB_POOL_RECYCLE,
echo=env.DB_ECHO,
),
"reader": create_async_engine(
env.DB_READER_DB_URL,
pool_recycle=env.DB_POOL_RECYCLE,
echo=env.DB_ECHO,
),
"auth": create_async_engine(
env.DB_AUTH_DB_URL,
pool_recycle=env.DB_POOL_RECYCLE,
echo=env.DB_ECHO,
),
}add __bind_key__ metadata in orm models to identify databases.
class Model(Base):
__tablename__ = "TABLE_NAME"
__bind_key__ = "auth" DB routing is performed according to the bind_key information in the get_bind() method of RoutingSession. If additional logic is needed, refer to RoutingSession in core/db/session.py and modify it.
refer the repo of starlette-admin