aiteamutils 0.2.40__py3-none-any.whl → 0.2.42__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
aiteamutils/database.py
CHANGED
@@ -47,8 +47,21 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
47
47
|
CustomException: 세션 생성 실패 시
|
48
48
|
"""
|
49
49
|
db_service = get_database_service()
|
50
|
+
if not db_service or not db_service.engine:
|
51
|
+
raise CustomException(
|
52
|
+
ErrorCode.DB_CONNECTION_ERROR,
|
53
|
+
detail="Database service or engine is not properly initialized",
|
54
|
+
source_function="get_db"
|
55
|
+
)
|
56
|
+
|
50
57
|
try:
|
51
58
|
async with db_service.get_session() as session:
|
59
|
+
if session is None:
|
60
|
+
raise CustomException(
|
61
|
+
ErrorCode.DB_CONNECTION_ERROR,
|
62
|
+
detail="Failed to create database session",
|
63
|
+
source_function="get_db"
|
64
|
+
)
|
52
65
|
yield session
|
53
66
|
except Exception as e:
|
54
67
|
raise CustomException(
|
@@ -58,7 +71,7 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|
58
71
|
original_error=e
|
59
72
|
)
|
60
73
|
finally:
|
61
|
-
if 'session' in locals():
|
74
|
+
if 'session' in locals() and session is not None:
|
62
75
|
await session.close()
|
63
76
|
|
64
77
|
def get_database_session(db: AsyncSession = Depends(get_db)) -> 'DatabaseService':
|
@@ -69,8 +82,26 @@ def get_database_session(db: AsyncSession = Depends(get_db)) -> 'DatabaseService
|
|
69
82
|
|
70
83
|
Returns:
|
71
84
|
DatabaseService: DatabaseService 인스턴스
|
85
|
+
|
86
|
+
Raises:
|
87
|
+
CustomException: 데이터베이스 세션이 유효하지 않은 경우
|
72
88
|
"""
|
73
|
-
|
89
|
+
if db is None:
|
90
|
+
raise CustomException(
|
91
|
+
ErrorCode.DB_CONNECTION_ERROR,
|
92
|
+
detail="Database session is not initialized",
|
93
|
+
source_function="get_database_session"
|
94
|
+
)
|
95
|
+
|
96
|
+
db_service = DatabaseService(session=db)
|
97
|
+
if db_service.db is None:
|
98
|
+
raise CustomException(
|
99
|
+
ErrorCode.DB_CONNECTION_ERROR,
|
100
|
+
detail="Failed to initialize database session",
|
101
|
+
source_function="get_database_session"
|
102
|
+
)
|
103
|
+
|
104
|
+
return db_service
|
74
105
|
|
75
106
|
class DatabaseService:
|
76
107
|
def __init__(
|
@@ -685,16 +716,33 @@ class DatabaseService:
|
|
685
716
|
|
686
717
|
Returns:
|
687
718
|
생성된 로그 엔티티
|
688
|
-
"""
|
689
|
-
# 공통 필드 추가 (ULID를 문자열로 변환)
|
690
|
-
log_data["ulid"] = str(ULID())
|
691
719
|
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
720
|
+
Raises:
|
721
|
+
CustomException: 로그 생성 실패 시
|
722
|
+
"""
|
723
|
+
try:
|
724
|
+
# 공통 필드 추가 (ULID를 문자열로 변환)
|
725
|
+
log_data["ulid"] = str(ULID())
|
726
|
+
|
727
|
+
# request가 있는 경우 user-agent와 ip 정보 추가
|
728
|
+
if request:
|
729
|
+
log_data["user_agent"] = request.headers.get("user-agent")
|
730
|
+
log_data["ip_address"] = request.headers.get("x-forwarded-for")
|
731
|
+
|
732
|
+
# 데이터 전처리
|
733
|
+
processed_data = self.preprocess_data(model, log_data)
|
734
|
+
entity = model(**processed_data)
|
735
|
+
|
736
|
+
# 로그 엔티티 저장
|
737
|
+
self.db.add(entity)
|
738
|
+
await self.db.flush()
|
739
|
+
|
740
|
+
return entity
|
741
|
+
|
742
|
+
except Exception as e:
|
743
|
+
logging.error(f"Failed to create log: {str(e)}")
|
744
|
+
# 로그 생성 실패는 원래 작업에 영향을 주지 않도록 함
|
745
|
+
return None
|
698
746
|
|
699
747
|
async def soft_delete(
|
700
748
|
self,
|
aiteamutils/version.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
"""버전 정보"""
|
2
|
-
__version__ = "0.2.
|
2
|
+
__version__ = "0.2.42"
|
@@ -4,13 +4,13 @@ aiteamutils/base_repository.py,sha256=qdwQ7Sj2fUqxpDg6cWM48n_QbwPK_VUlG9zTSem8iC
|
|
4
4
|
aiteamutils/base_service.py,sha256=E4dHGE0DvhmRyFplh46SwKJOSF_nUL7OAsCkf_ZJF_8,24733
|
5
5
|
aiteamutils/cache.py,sha256=tr0Yn8VPYA9QHiKCUzciVlQ2J1RAwNo2K9lGMH4rY3s,1334
|
6
6
|
aiteamutils/config.py,sha256=kFKMeIx1KcuEwwx4VjZdCgoTOHCkG3ySYVJ0G6cvMoA,2849
|
7
|
-
aiteamutils/database.py,sha256=
|
7
|
+
aiteamutils/database.py,sha256=oI36mW94Hnn5laS3YcsAyuofFsQzbj3TXT-HRb3SYk8,37029
|
8
8
|
aiteamutils/dependencies.py,sha256=hsJ-kc8ic4U6vKFtUIWjhBE1_Bm-sya5UqSb2zMH5oM,5731
|
9
9
|
aiteamutils/enums.py,sha256=ipZi6k_QD5-3QV7Yzv7bnL0MjDz-vqfO9I5L77biMKs,632
|
10
10
|
aiteamutils/exceptions.py,sha256=_lKWXq_ujNj41xN6LDE149PwsecAP7lgYWbOBbLOntg,15368
|
11
11
|
aiteamutils/security.py,sha256=9gvEqDtE3RJaoCWqELPCjkg-IsSqZVrpMP6XPZaodWU,16024
|
12
12
|
aiteamutils/validators.py,sha256=3N245cZFjgwtW_KzjESkizx5BBUDaJLbbxfNO4WOFZ0,7764
|
13
|
-
aiteamutils/version.py,sha256=
|
14
|
-
aiteamutils-0.2.
|
15
|
-
aiteamutils-0.2.
|
16
|
-
aiteamutils-0.2.
|
13
|
+
aiteamutils/version.py,sha256=smfyzeeMHy2PIy96IdATpp51v_Y3aEPYazLKs09uNSM,42
|
14
|
+
aiteamutils-0.2.42.dist-info/METADATA,sha256=Bn-kxta6CUfeOYPzE03yrlm-4k5p5NqKOzln7YB9E7U,1718
|
15
|
+
aiteamutils-0.2.42.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
aiteamutils-0.2.42.dist-info/RECORD,,
|
File without changes
|