From fb314216560ce43c6c829c5197401299e7637d71 Mon Sep 17 00:00:00 2001 From: "yukun.wyk" Date: Mon, 16 Sep 2024 23:49:46 +0800 Subject: [PATCH] fix(api): avoid config conflict --- api/{config.py => api_config.py} | 0 api/dao/account.py | 2 +- api/db.py | 7 +++++-- api/main.py | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) rename api/{config.py => api_config.py} (100%) diff --git a/api/config.py b/api/api_config.py similarity index 100% rename from api/config.py rename to api/api_config.py diff --git a/api/dao/account.py b/api/dao/account.py index f9b5269..40ee0c5 100644 --- a/api/dao/account.py +++ b/api/dao/account.py @@ -2,7 +2,7 @@ from sqlalchemy.orm import Session from models.account import AccountCreate, AccountORM, AccountStatus -from config import settings +from api_config import settings class AccountHelper: diff --git a/api/db.py b/api/db.py index 469015e..6f68108 100644 --- a/api/db.py +++ b/api/db.py @@ -2,9 +2,9 @@ from typing import Generator from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import sessionmaker,Session +from sqlalchemy.orm import sessionmaker, Session -from config import settings +from api_config import settings SQLALCHEMY_DATABASE_URL = str(settings.SQLALCHEMY_DATABASE_URI) @@ -14,6 +14,8 @@ Base = declarative_base() # 上下文管理器用于手动管理会话 + + @contextmanager def get_session() -> Generator[Session, None, None]: session = SessionLocal() @@ -22,6 +24,7 @@ def get_session() -> Generator[Session, None, None]: finally: session.close() + def get_db(): try: db = SessionLocal() diff --git a/api/main.py b/api/main.py index 7369066..d7527a8 100644 --- a/api/main.py +++ b/api/main.py @@ -6,7 +6,7 @@ from db import SessionLocal -from config import settings +from api_config import settings with SessionLocal() as session: