mirror of
https://github.com/fastapi-practices/fastapi_best_architecture.git
synced 2026-03-13 09:31:31 +08:00
* feat: add postgresql db supports * change: change mysql conn str create way * fix: Modify the default alembic migration file to meet multi-database support * Update settings and lint * update models * Simplify database config * Simplify the get db method * Update create db url * Updated model type adaptation * Update sql scripts * Fix models type * Adaptation to postgresql code generation * Update README.md * Fix alembic file template * Update docker scripts
22 lines
591 B
Python
22 lines
591 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from backend.database.db import create_database_url, create_engine_and_session
|
|
|
|
TEST_SQLALCHEMY_DATABASE_URL = create_database_url(unittest=True)
|
|
|
|
_, async_test_db_session = create_engine_and_session(TEST_SQLALCHEMY_DATABASE_URL)
|
|
|
|
|
|
async def override_get_db() -> AsyncSession:
|
|
"""session 生成器"""
|
|
session = async_test_db_session()
|
|
try:
|
|
yield session
|
|
except Exception as se:
|
|
await session.rollback()
|
|
raise se
|
|
finally:
|
|
await session.close()
|