aiteamutils 0.2.50__tar.gz → 0.2.51__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aiteamutils
3
- Version: 0.2.50
3
+ Version: 0.2.51
4
4
  Summary: AI Team Utilities
5
5
  Project-URL: Homepage, https://github.com/yourusername/aiteamutils
6
6
  Project-URL: Issues, https://github.com/yourusername/aiteamutils/issues
@@ -997,62 +997,30 @@ class DatabaseService:
997
997
  )
998
998
 
999
999
  async def get_db() -> AsyncGenerator[AsyncSession, None]:
1000
- """데이터베이스 세션을 생성하고 반환하는 비동기 제너레이터.
1001
-
1000
+ """데이터베이스 세션 의존성
1001
+
1002
1002
  Yields:
1003
1003
  AsyncSession: 데이터베이스 세션
1004
-
1004
+
1005
1005
  Raises:
1006
- CustomException: 세션 생성 실패 시
1006
+ CustomException: 데이터베이스 연결 오류
1007
1007
  """
1008
- if not await DatabaseServiceManager.is_initialized():
1009
- raise CustomException(
1010
- ErrorCode.DB_CONNECTION_ERROR,
1011
- detail="Database service is not initialized",
1012
- source_function="get_db"
1013
- )
1014
-
1015
- db_service = await DatabaseServiceManager.get_instance()
1016
- if not db_service or not db_service.engine:
1017
- raise CustomException(
1018
- ErrorCode.DB_CONNECTION_ERROR,
1019
- detail="Database service or engine is not properly initialized",
1020
- source_function="get_db"
1021
- )
1008
+ db_service = await get_database_service()
1022
1009
 
1023
- try:
1024
- session = db_service.get_session()
1025
- if session is None:
1026
- raise CustomException(
1027
- ErrorCode.DB_CONNECTION_ERROR,
1028
- detail="Failed to create database session",
1029
- source_function="get_db"
1030
- )
1031
-
1032
- # 세션이 유효한지 확인
1010
+ async with db_service.get_session() as session:
1033
1011
  try:
1012
+ # 세션이 유효한지 확인
1034
1013
  await session.execute(select(1))
1014
+ yield session
1035
1015
  except Exception as e:
1036
- await session.close()
1016
+ if isinstance(e, CustomException):
1017
+ raise e
1037
1018
  raise CustomException(
1038
1019
  ErrorCode.DB_CONNECTION_ERROR,
1039
- detail="Database session is not valid",
1020
+ detail=f"Failed to get database session: {str(e)}",
1040
1021
  source_function="get_db",
1041
1022
  original_error=e
1042
1023
  )
1043
-
1044
- yield session
1045
- except Exception as e:
1046
- if isinstance(e, CustomException):
1047
- raise e
1048
- raise CustomException(
1049
- ErrorCode.DB_CONNECTION_ERROR,
1050
- detail=f"Failed to get database session: {str(e)}",
1051
- source_function="get_db",
1052
- original_error=e
1053
- )
1054
- finally:
1055
- await session.close()
1056
1024
 
1057
1025
  async def get_database_service() -> DatabaseService:
1058
1026
  """DatabaseService 의존성
@@ -0,0 +1,2 @@
1
+ """버전 정보"""
2
+ __version__ = "0.2.51"
@@ -1,2 +0,0 @@
1
- """버전 정보"""
2
- __version__ = "0.2.50"
File without changes
File without changes
File without changes
File without changes