mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-20 20:39:55 +00:00
feat(database): 增加对postgresql的支持并优化数据库配置
扩展数据库驱动支持,添加postgresql选项 重构数据库连接配置,分离同步和异步引擎 添加菜单常量和更新业务操作类型枚举 新增MySQL配置文件并更新依赖项 优化任务调度器的事件处理和日志记录
This commit is contained in:
@@ -28,8 +28,15 @@ from app.core.logger import logger
|
||||
from app.config.setting import settings
|
||||
from app.core.exceptions import CustomException
|
||||
|
||||
# 同步数据库引擎
|
||||
engine = create_engine(
|
||||
url=settings.DATABASES_URI,
|
||||
echo=settings.DATABASE_ECHO,
|
||||
)
|
||||
# 同步数据库会话工厂
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
|
||||
# 异步数据库引擎
|
||||
def async_db_engine() -> AsyncEngine:
|
||||
"""创建异步数据库引擎"""
|
||||
# 创建数据库引擎
|
||||
@@ -47,8 +54,7 @@ def async_db_engine() -> AsyncEngine:
|
||||
|
||||
return async_engine
|
||||
|
||||
|
||||
# 创建会话工厂
|
||||
# 异步数据库会话工厂
|
||||
async_session = async_sessionmaker(
|
||||
bind=async_db_engine(),
|
||||
autocommit=settings.AUTOCOMMIT,
|
||||
@@ -57,7 +63,6 @@ async_session = async_sessionmaker(
|
||||
class_=AsyncSession
|
||||
)
|
||||
|
||||
|
||||
def session_connect() -> AsyncSession:
|
||||
"""获取数据库会话"""
|
||||
try:
|
||||
@@ -126,7 +131,6 @@ async def redis_connect(app: FastAPI, status: bool) -> aioredis.Redis:
|
||||
await app.state.redis.close()
|
||||
logger.info('Redis连接已关闭')
|
||||
|
||||
|
||||
async def mongodb_connect(app: FastAPI, status: bool) -> AsyncIOMotorClient:
|
||||
"""创建或关闭MongoDB连接"""
|
||||
if not settings.MONGO_DB_ENABLE:
|
||||
|
||||
Reference in New Issue
Block a user