Correct stop of loop, mysql and influx
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
||||
from sqlalchemy.ext.asyncio import (create_async_engine, AsyncSession,
|
||||
async_sessionmaker, AsyncEngine)
|
||||
|
||||
mysql_engine = None
|
||||
|
||||
mysql_engine: AsyncEngine
|
||||
mysql_SessionLocal: async_sessionmaker
|
||||
|
||||
|
||||
def mysql_init(db_type: str, host: str, port: int, db_name: str, user: str, password: str):
|
||||
"""Initialize DB engine + session factory"""
|
||||
global mysql_engine, mysql_SessionLocal
|
||||
@@ -37,11 +38,13 @@ def mysql_init(db_type: str, host: str, port: int, db_name: str, user: str, pass
|
||||
)
|
||||
print(f"mysql_SessionLocal: {mysql_SessionLocal}")
|
||||
|
||||
def get_session_local() -> AsyncSession:
|
||||
return mysql_SessionLocal()
|
||||
def get_mysql_engine() -> AsyncEngine:
|
||||
return mysql_engine
|
||||
|
||||
def get_mysql_session_local() -> AsyncSession:
|
||||
return mysql_SessionLocal()
|
||||
|
||||
async def get_mysql_db():
|
||||
"""FastAPI dependency for providing DB sessions"""
|
||||
async with get_session_local() as session:
|
||||
async with get_mysql_session_local() as session:
|
||||
yield session
|
||||
|
||||
Reference in New Issue
Block a user