aiteamutils 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aiteamutils/base_repository.py +3 -3
- aiteamutils/base_service.py +1 -1
- aiteamutils/database.py +30 -30
- aiteamutils/validators.py +1 -1
- {aiteamutils-0.2.0.dist-info → aiteamutils-0.2.2.dist-info}/METADATA +7 -7
- {aiteamutils-0.2.0.dist-info → aiteamutils-0.2.2.dist-info}/RECORD +7 -7
- {aiteamutils-0.2.0.dist-info → aiteamutils-0.2.2.dist-info}/WHEEL +0 -0
aiteamutils/base_repository.py
CHANGED
@@ -3,7 +3,7 @@ from typing import TypeVar, Generic, Dict, Any, List, Optional, Type
|
|
3
3
|
from sqlalchemy.orm import DeclarativeBase
|
4
4
|
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
5
5
|
from sqlalchemy import select, or_, and_
|
6
|
-
from .database import
|
6
|
+
from .database import DatabaseManager
|
7
7
|
from .exceptions import CustomException, ErrorCode
|
8
8
|
from sqlalchemy.orm import joinedload
|
9
9
|
from sqlalchemy.sql import Select
|
@@ -14,10 +14,10 @@ class BaseRepository(Generic[ModelType]):
|
|
14
14
|
##################
|
15
15
|
# 1. 초기화 영역 #
|
16
16
|
##################
|
17
|
-
def __init__(self, db_service:
|
17
|
+
def __init__(self, db_service: DatabaseManager, model: Type[ModelType]):
|
18
18
|
"""
|
19
19
|
Args:
|
20
|
-
db_service (
|
20
|
+
db_service (DatabaseManager): 데이터베이스 서비스 인스턴스
|
21
21
|
model (Type[ModelType]): 모델 클래스
|
22
22
|
"""
|
23
23
|
self.db_service = db_service
|
aiteamutils/base_service.py
CHANGED
@@ -3,7 +3,7 @@ from datetime import datetime
|
|
3
3
|
from typing import TypeVar, Generic, Dict, Any, List, Optional, Type, Union
|
4
4
|
from sqlalchemy.orm import DeclarativeBase
|
5
5
|
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
|
6
|
-
from .database import
|
6
|
+
from .database import DatabaseManager
|
7
7
|
from .exceptions import CustomException, ErrorCode
|
8
8
|
from .base_repository import BaseRepository
|
9
9
|
from .security import hash_password
|
aiteamutils/database.py
CHANGED
@@ -17,9 +17,9 @@ from .config import settings
|
|
17
17
|
|
18
18
|
T = TypeVar("T", bound=BaseColumn)
|
19
19
|
|
20
|
-
class
|
20
|
+
class DatabaseManager:
|
21
21
|
def __init__(self, db_url: str):
|
22
|
-
"""
|
22
|
+
"""DatabaseManager 초기화.
|
23
23
|
|
24
24
|
Args:
|
25
25
|
db_url: 데이터베이스 URL
|
@@ -173,7 +173,7 @@ class DatabaseService:
|
|
173
173
|
raise CustomException(
|
174
174
|
ErrorCode.DUPLICATE_ERROR,
|
175
175
|
detail=f"{model.__tablename__}|{field}|{value}",
|
176
|
-
source_function="
|
176
|
+
source_function="DatabaseManager.create_entity",
|
177
177
|
original_error=e
|
178
178
|
)
|
179
179
|
elif "violates foreign key constraint" in error_str.lower():
|
@@ -181,14 +181,14 @@ class DatabaseService:
|
|
181
181
|
raise CustomException(
|
182
182
|
ErrorCode.FOREIGN_KEY_VIOLATION,
|
183
183
|
detail=error_str,
|
184
|
-
source_function="
|
184
|
+
source_function="DatabaseManager.create_entity",
|
185
185
|
original_error=e
|
186
186
|
)
|
187
187
|
else:
|
188
188
|
raise CustomException(
|
189
189
|
ErrorCode.DB_CREATE_ERROR,
|
190
190
|
detail=f"Failed to create {model.__name__}: {str(e)}",
|
191
|
-
source_function="
|
191
|
+
source_function="DatabaseManager.create_entity",
|
192
192
|
original_error=e
|
193
193
|
)
|
194
194
|
except CustomException as e:
|
@@ -199,7 +199,7 @@ class DatabaseService:
|
|
199
199
|
raise CustomException(
|
200
200
|
ErrorCode.UNEXPECTED_ERROR,
|
201
201
|
detail=f"Unexpected error while creating {model.__name__}: {str(e)}",
|
202
|
-
source_function="
|
202
|
+
source_function="DatabaseManager.create_entity",
|
203
203
|
original_error=e
|
204
204
|
)
|
205
205
|
|
@@ -243,7 +243,7 @@ class DatabaseService:
|
|
243
243
|
raise CustomException(
|
244
244
|
ErrorCode.DB_QUERY_ERROR,
|
245
245
|
detail=str(e),
|
246
|
-
source_function="
|
246
|
+
source_function="DatabaseManager.retrieve_entity",
|
247
247
|
original_error=e
|
248
248
|
)
|
249
249
|
|
@@ -307,7 +307,7 @@ class DatabaseService:
|
|
307
307
|
raise CustomException(
|
308
308
|
ErrorCode.DB_UPDATE_ERROR,
|
309
309
|
detail=f"Failed to update {model.__name__}: {str(e)}",
|
310
|
-
source_function="
|
310
|
+
source_function="DatabaseManager.update_entity",
|
311
311
|
original_error=e
|
312
312
|
)
|
313
313
|
except Exception as e:
|
@@ -315,7 +315,7 @@ class DatabaseService:
|
|
315
315
|
raise CustomException(
|
316
316
|
ErrorCode.UNEXPECTED_ERROR,
|
317
317
|
detail=f"Unexpected error while updating {model.__name__}: {str(e)}",
|
318
|
-
source_function="
|
318
|
+
source_function="DatabaseManager.update_entity",
|
319
319
|
original_error=e
|
320
320
|
)
|
321
321
|
|
@@ -337,7 +337,7 @@ class DatabaseService:
|
|
337
337
|
raise CustomException(
|
338
338
|
ErrorCode.DB_DELETE_ERROR,
|
339
339
|
detail=f"Failed to delete entity: {str(e)}",
|
340
|
-
source_function="
|
340
|
+
source_function="DatabaseManager.delete_entity",
|
341
341
|
original_error=e
|
342
342
|
)
|
343
343
|
except Exception as e:
|
@@ -345,7 +345,7 @@ class DatabaseService:
|
|
345
345
|
raise CustomException(
|
346
346
|
ErrorCode.UNEXPECTED_ERROR,
|
347
347
|
detail=f"Unexpected error while deleting entity: {str(e)}",
|
348
|
-
source_function="
|
348
|
+
source_function="DatabaseManager.delete_entity",
|
349
349
|
original_error=e
|
350
350
|
)
|
351
351
|
|
@@ -392,7 +392,7 @@ class DatabaseService:
|
|
392
392
|
raise CustomException(
|
393
393
|
ErrorCode.DB_DELETE_ERROR,
|
394
394
|
detail=f"Failed to soft delete {model.__name__}: {str(e)}",
|
395
|
-
source_function="
|
395
|
+
source_function="DatabaseManager.soft_delete_entity",
|
396
396
|
original_error=e
|
397
397
|
)
|
398
398
|
except Exception as e:
|
@@ -400,7 +400,7 @@ class DatabaseService:
|
|
400
400
|
raise CustomException(
|
401
401
|
ErrorCode.UNEXPECTED_ERROR,
|
402
402
|
detail=f"Unexpected error while soft deleting {model.__name__}: {str(e)}",
|
403
|
-
source_function="
|
403
|
+
source_function="DatabaseManager.soft_delete_entity",
|
404
404
|
original_error=e
|
405
405
|
)
|
406
406
|
|
@@ -468,14 +468,14 @@ class DatabaseService:
|
|
468
468
|
raise CustomException(
|
469
469
|
ErrorCode.DB_READ_ERROR,
|
470
470
|
detail=f"Failed to list {model.__name__}: {str(e)}",
|
471
|
-
source_function="
|
471
|
+
source_function="DatabaseManager.list_entities",
|
472
472
|
original_error=e
|
473
473
|
)
|
474
474
|
except Exception as e:
|
475
475
|
raise CustomException(
|
476
476
|
ErrorCode.UNEXPECTED_ERROR,
|
477
477
|
detail=f"Unexpected error while listing {model.__name__}: {str(e)}",
|
478
|
-
source_function="
|
478
|
+
source_function="DatabaseManager.list_entities",
|
479
479
|
original_error=e
|
480
480
|
)
|
481
481
|
|
@@ -524,14 +524,14 @@ class DatabaseService:
|
|
524
524
|
raise CustomException(
|
525
525
|
error_code,
|
526
526
|
detail=detail,
|
527
|
-
source_function="
|
527
|
+
source_function="DatabaseManager.validate_unique_fields"
|
528
528
|
)
|
529
529
|
|
530
530
|
except CustomException as e:
|
531
531
|
raise CustomException(
|
532
532
|
e.error_code,
|
533
533
|
detail=e.detail,
|
534
|
-
source_function="
|
534
|
+
source_function="DatabaseManager.validate_unique_fields",
|
535
535
|
original_error=e.original_error,
|
536
536
|
parent_source_function=e.source_function
|
537
537
|
)
|
@@ -539,7 +539,7 @@ class DatabaseService:
|
|
539
539
|
raise CustomException(
|
540
540
|
ErrorCode.DB_QUERY_ERROR,
|
541
541
|
detail=str(e),
|
542
|
-
source_function="
|
542
|
+
source_function="DatabaseManager.validate_unique_fields",
|
543
543
|
original_error=e
|
544
544
|
)
|
545
545
|
|
@@ -577,7 +577,7 @@ class DatabaseService:
|
|
577
577
|
raise CustomException(
|
578
578
|
ErrorCode.FOREIGN_KEY_VIOLATION,
|
579
579
|
detail=f"{referenced_table.name}|{field}|{value}",
|
580
|
-
source_function="
|
580
|
+
source_function="DatabaseManager.validate_foreign_key_fields"
|
581
581
|
)
|
582
582
|
|
583
583
|
#######################
|
@@ -637,7 +637,7 @@ class DatabaseService:
|
|
637
637
|
raise CustomException(
|
638
638
|
ErrorCode.NOT_FOUND,
|
639
639
|
detail=f"{model.__name__}|{entity_id}",
|
640
|
-
source_function=source_function or "
|
640
|
+
source_function=source_function or "DatabaseManager.soft_delete"
|
641
641
|
)
|
642
642
|
|
643
643
|
# 2. 소프트 삭제 처리
|
@@ -665,7 +665,7 @@ class DatabaseService:
|
|
665
665
|
raise CustomException(
|
666
666
|
e.error_code,
|
667
667
|
detail=e.detail,
|
668
|
-
source_function=source_function or "
|
668
|
+
source_function=source_function or "DatabaseManager.soft_delete",
|
669
669
|
original_error=e.original_error,
|
670
670
|
parent_source_function=e.source_function
|
671
671
|
)
|
@@ -674,7 +674,7 @@ class DatabaseService:
|
|
674
674
|
raise CustomException(
|
675
675
|
ErrorCode.DB_DELETE_ERROR,
|
676
676
|
detail=str(e),
|
677
|
-
source_function=source_function or "
|
677
|
+
source_function=source_function or "DatabaseManager.soft_delete",
|
678
678
|
original_error=e
|
679
679
|
)
|
680
680
|
|
@@ -704,14 +704,14 @@ class DatabaseService:
|
|
704
704
|
raise CustomException(
|
705
705
|
ErrorCode.DB_READ_ERROR,
|
706
706
|
detail=f"Failed to get {model.__name__}: {str(e)}",
|
707
|
-
source_function="
|
707
|
+
source_function="DatabaseManager.get_entity",
|
708
708
|
original_error=e
|
709
709
|
)
|
710
710
|
except Exception as e:
|
711
711
|
raise CustomException(
|
712
712
|
ErrorCode.UNEXPECTED_ERROR,
|
713
713
|
detail=f"Unexpected error while getting {model.__name__}: {str(e)}",
|
714
|
-
source_function="
|
714
|
+
source_function="DatabaseManager.get_entity",
|
715
715
|
original_error=e
|
716
716
|
)
|
717
717
|
|
@@ -757,14 +757,14 @@ class DatabaseService:
|
|
757
757
|
raise CustomException(
|
758
758
|
ErrorCode.DB_QUERY_ERROR,
|
759
759
|
detail=str(e),
|
760
|
-
source_function="
|
760
|
+
source_function="DatabaseManager.execute",
|
761
761
|
original_error=e
|
762
762
|
)
|
763
763
|
except Exception as e:
|
764
764
|
raise CustomException(
|
765
765
|
ErrorCode.UNEXPECTED_ERROR,
|
766
766
|
detail=str(e),
|
767
|
-
source_function="
|
767
|
+
source_function="DatabaseManager.execute",
|
768
768
|
original_error=e
|
769
769
|
)
|
770
770
|
|
@@ -777,7 +777,7 @@ class DatabaseService:
|
|
777
777
|
raise CustomException(
|
778
778
|
ErrorCode.DB_QUERY_ERROR,
|
779
779
|
detail=str(e),
|
780
|
-
source_function="
|
780
|
+
source_function="DatabaseManager.commit",
|
781
781
|
original_error=e
|
782
782
|
)
|
783
783
|
|
@@ -789,7 +789,7 @@ class DatabaseService:
|
|
789
789
|
raise CustomException(
|
790
790
|
ErrorCode.DB_QUERY_ERROR,
|
791
791
|
detail=str(e),
|
792
|
-
source_function="
|
792
|
+
source_function="DatabaseManager.rollback",
|
793
793
|
original_error=e
|
794
794
|
)
|
795
795
|
|
@@ -802,7 +802,7 @@ class DatabaseService:
|
|
802
802
|
raise CustomException(
|
803
803
|
ErrorCode.DB_QUERY_ERROR,
|
804
804
|
detail=str(e),
|
805
|
-
source_function="
|
805
|
+
source_function="DatabaseManager.flush",
|
806
806
|
original_error=e
|
807
807
|
)
|
808
808
|
|
@@ -818,6 +818,6 @@ class DatabaseService:
|
|
818
818
|
raise CustomException(
|
819
819
|
ErrorCode.DB_QUERY_ERROR,
|
820
820
|
detail=str(e),
|
821
|
-
source_function="
|
821
|
+
source_function="DatabaseManager.refresh",
|
822
822
|
original_error=e
|
823
823
|
)
|
aiteamutils/validators.py
CHANGED
@@ -7,7 +7,7 @@ from pydantic import field_validator
|
|
7
7
|
import re
|
8
8
|
|
9
9
|
from .exceptions import ErrorCode, CustomException
|
10
|
-
from .database import
|
10
|
+
from .database import DatabaseManager
|
11
11
|
from .base_model import Base
|
12
12
|
|
13
13
|
def validate_with(validator_func, unique_check=None, skip_if_none=False):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: aiteamutils
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.2
|
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
|
@@ -14,21 +14,21 @@ Requires-Dist: python-jose
|
|
14
14
|
Requires-Dist: sqlalchemy
|
15
15
|
Description-Content-Type: text/markdown
|
16
16
|
|
17
|
-
# AI Team
|
17
|
+
# AI Team Utils
|
18
18
|
|
19
|
-
AI Team
|
19
|
+
AI Team의 공통 유틸리티 패키지입니다.
|
20
20
|
|
21
21
|
## 설치 방법
|
22
22
|
|
23
23
|
```bash
|
24
|
-
pip install
|
24
|
+
pip install aiteamutils
|
25
25
|
```
|
26
26
|
|
27
27
|
## 사용 예시
|
28
28
|
|
29
29
|
```python
|
30
|
-
from
|
31
|
-
from
|
30
|
+
from aiteamutils.database import DatabaseManager
|
31
|
+
from aiteamutils.base_model import Base
|
32
32
|
|
33
33
|
# DB 매니저 초기화
|
34
34
|
db = DatabaseManager("postgresql+asyncpg://user:pass@localhost/db")
|
@@ -39,7 +39,7 @@ async with db.get_session() as session:
|
|
39
39
|
pass
|
40
40
|
|
41
41
|
# 예외 처리
|
42
|
-
from
|
42
|
+
from aiteamutils.exceptions import CustomException, ErrorCode
|
43
43
|
|
44
44
|
try:
|
45
45
|
# 작업 수행
|
@@ -1,15 +1,15 @@
|
|
1
1
|
aiteamutils/__init__.py,sha256=zmfBXBwNWdbJKCt1rmHk_czHJLmVF-oqRuqq8tf0t0U,1229
|
2
2
|
aiteamutils/base_model.py,sha256=ODEnjvUVoxQ1RPCfq8-uZTfTADIA4c7Z3E6G4EVsSX0,2708
|
3
|
-
aiteamutils/base_repository.py,sha256=
|
4
|
-
aiteamutils/base_service.py,sha256=
|
3
|
+
aiteamutils/base_repository.py,sha256=TQAXajQaaXIAJAFr9n5R2ikcu1TSq-E-_AjXgsND5c4,18927
|
4
|
+
aiteamutils/base_service.py,sha256=cqPP74ya6r8twJyU3Bc6ARxKiRL8fQIIZZnhDHxBQXE,24727
|
5
5
|
aiteamutils/cache.py,sha256=tr0Yn8VPYA9QHiKCUzciVlQ2J1RAwNo2K9lGMH4rY3s,1334
|
6
6
|
aiteamutils/config.py,sha256=vC6k6E2-Y4mD0E0kw6WVgSatCl9K_BtTwrVFhLrhCzs,665
|
7
|
-
aiteamutils/database.py,sha256=
|
7
|
+
aiteamutils/database.py,sha256=NwLgDIGSaWTORR5eU3W2rYSUlKPKJCWqF2f5yzLyf7A,29952
|
8
8
|
aiteamutils/dependencies.py,sha256=EJeVtq_lACuoheVhkX23N9xiak9bGD-t3-2JtlgBki0,4850
|
9
9
|
aiteamutils/enums.py,sha256=ipZi6k_QD5-3QV7Yzv7bnL0MjDz-vqfO9I5L77biMKs,632
|
10
10
|
aiteamutils/exceptions.py,sha256=YV-ISya4wQlHk4twvGo16I5r8h22-tXpn9wa-b3WwDM,15231
|
11
11
|
aiteamutils/security.py,sha256=AZszaTxVEGi1jU1sX3QXHGgshp1lVvd0xXvZejXvs_w,12643
|
12
|
-
aiteamutils/validators.py,sha256=
|
13
|
-
aiteamutils-0.2.
|
14
|
-
aiteamutils-0.2.
|
15
|
-
aiteamutils-0.2.
|
12
|
+
aiteamutils/validators.py,sha256=GA2idwDtbQynle7tya10cAnJ6DvLIFsJ746We0V-30k,7630
|
13
|
+
aiteamutils-0.2.2.dist-info/METADATA,sha256=kOqyfN5HkeRdM6L7jEttopFCIbbFxQLqKdxWQhtLLT0,1527
|
14
|
+
aiteamutils-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
15
|
+
aiteamutils-0.2.2.dist-info/RECORD,,
|
File without changes
|