aiteamutils 0.2.2__tar.gz → 0.2.3__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/PKG-INFO +12 -6
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/README.md +11 -5
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/__init__.py +3 -4
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/database.py +30 -30
- aiteamutils-0.2.3/aiteamutils/version.py +2 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/pyproject.toml +4 -1
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/.gitignore +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/base_model.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/base_repository.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/base_service.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/cache.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/config.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/dependencies.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/enums.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/exceptions.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/security.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/aiteamutils/validators.py +0 -0
- {aiteamutils-0.2.2 → aiteamutils-0.2.3}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: aiteamutils
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.3
|
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
|
@@ -27,17 +27,21 @@ pip install aiteamutils
|
|
27
27
|
## 사용 예시
|
28
28
|
|
29
29
|
```python
|
30
|
-
from aiteamutils.database import
|
31
|
-
from aiteamutils.base_model import Base
|
30
|
+
from aiteamutils.database import DatabaseService
|
32
31
|
|
33
|
-
# DB
|
34
|
-
|
32
|
+
# DB 서비스 초기화
|
33
|
+
db_service = DatabaseService("postgresql+asyncpg://user:pass@localhost/db")
|
35
34
|
|
36
35
|
# DB 세션 사용
|
37
|
-
async with
|
36
|
+
async with db_service.get_db() as session:
|
38
37
|
# DB 작업 수행
|
39
38
|
pass
|
40
39
|
|
40
|
+
# 트랜잭션 사용
|
41
|
+
async with db_service.transaction():
|
42
|
+
# 트랜잭션 내 작업 수행
|
43
|
+
result = await db_service.create_entity(UserModel, {"name": "test"})
|
44
|
+
|
41
45
|
# 예외 처리
|
42
46
|
from aiteamutils.exceptions import CustomException, ErrorCode
|
43
47
|
|
@@ -55,6 +59,8 @@ except CustomException as e:
|
|
55
59
|
- 세션 관리
|
56
60
|
- 트랜잭션 관리
|
57
61
|
- 기본 CRUD 작업
|
62
|
+
- 외래키 검증
|
63
|
+
- 유니크 필드 검증
|
58
64
|
|
59
65
|
- 인증/인가 유틸리티
|
60
66
|
- JWT 토큰 관리
|
@@ -11,17 +11,21 @@ pip install aiteamutils
|
|
11
11
|
## 사용 예시
|
12
12
|
|
13
13
|
```python
|
14
|
-
from aiteamutils.database import
|
15
|
-
from aiteamutils.base_model import Base
|
14
|
+
from aiteamutils.database import DatabaseService
|
16
15
|
|
17
|
-
# DB
|
18
|
-
|
16
|
+
# DB 서비스 초기화
|
17
|
+
db_service = DatabaseService("postgresql+asyncpg://user:pass@localhost/db")
|
19
18
|
|
20
19
|
# DB 세션 사용
|
21
|
-
async with
|
20
|
+
async with db_service.get_db() as session:
|
22
21
|
# DB 작업 수행
|
23
22
|
pass
|
24
23
|
|
24
|
+
# 트랜잭션 사용
|
25
|
+
async with db_service.transaction():
|
26
|
+
# 트랜잭션 내 작업 수행
|
27
|
+
result = await db_service.create_entity(UserModel, {"name": "test"})
|
28
|
+
|
25
29
|
# 예외 처리
|
26
30
|
from aiteamutils.exceptions import CustomException, ErrorCode
|
27
31
|
|
@@ -39,6 +43,8 @@ except CustomException as e:
|
|
39
43
|
- 세션 관리
|
40
44
|
- 트랜잭션 관리
|
41
45
|
- 기본 CRUD 작업
|
46
|
+
- 외래키 검증
|
47
|
+
- 유니크 필드 검증
|
42
48
|
|
43
49
|
- 인증/인가 유틸리티
|
44
50
|
- JWT 토큰 관리
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from .base_model import Base
|
2
|
-
from .database import
|
2
|
+
from .database import DatabaseService
|
3
3
|
from .exceptions import (
|
4
4
|
CustomException,
|
5
5
|
ErrorCode,
|
@@ -21,8 +21,7 @@ from .base_repository import BaseRepository
|
|
21
21
|
from .validators import validate_with
|
22
22
|
from .enums import ActivityType
|
23
23
|
from .cache import CacheManager
|
24
|
-
|
25
|
-
__version__ = "0.1.0"
|
24
|
+
from .version import __version__
|
26
25
|
|
27
26
|
__all__ = [
|
28
27
|
# Base Models
|
@@ -31,7 +30,7 @@ __all__ = [
|
|
31
30
|
"BaseRepository",
|
32
31
|
|
33
32
|
# Database
|
34
|
-
"
|
33
|
+
"DatabaseService",
|
35
34
|
|
36
35
|
# Exceptions
|
37
36
|
"CustomException",
|
@@ -17,9 +17,9 @@ from .config import settings
|
|
17
17
|
|
18
18
|
T = TypeVar("T", bound=BaseColumn)
|
19
19
|
|
20
|
-
class
|
20
|
+
class DatabaseService:
|
21
21
|
def __init__(self, db_url: str):
|
22
|
-
"""
|
22
|
+
"""DatabaseService 초기화.
|
23
23
|
|
24
24
|
Args:
|
25
25
|
db_url: 데이터베이스 URL
|
@@ -173,7 +173,7 @@ class DatabaseManager:
|
|
173
173
|
raise CustomException(
|
174
174
|
ErrorCode.DUPLICATE_ERROR,
|
175
175
|
detail=f"{model.__tablename__}|{field}|{value}",
|
176
|
-
source_function="
|
176
|
+
source_function="DatabaseService.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 DatabaseManager:
|
|
181
181
|
raise CustomException(
|
182
182
|
ErrorCode.FOREIGN_KEY_VIOLATION,
|
183
183
|
detail=error_str,
|
184
|
-
source_function="
|
184
|
+
source_function="DatabaseService.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="DatabaseService.create_entity",
|
192
192
|
original_error=e
|
193
193
|
)
|
194
194
|
except CustomException as e:
|
@@ -199,7 +199,7 @@ class DatabaseManager:
|
|
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="DatabaseService.create_entity",
|
203
203
|
original_error=e
|
204
204
|
)
|
205
205
|
|
@@ -243,7 +243,7 @@ class DatabaseManager:
|
|
243
243
|
raise CustomException(
|
244
244
|
ErrorCode.DB_QUERY_ERROR,
|
245
245
|
detail=str(e),
|
246
|
-
source_function="
|
246
|
+
source_function="DatabaseService.retrieve_entity",
|
247
247
|
original_error=e
|
248
248
|
)
|
249
249
|
|
@@ -307,7 +307,7 @@ class DatabaseManager:
|
|
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="DatabaseService.update_entity",
|
311
311
|
original_error=e
|
312
312
|
)
|
313
313
|
except Exception as e:
|
@@ -315,7 +315,7 @@ class DatabaseManager:
|
|
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="DatabaseService.update_entity",
|
319
319
|
original_error=e
|
320
320
|
)
|
321
321
|
|
@@ -337,7 +337,7 @@ class DatabaseManager:
|
|
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="DatabaseService.delete_entity",
|
341
341
|
original_error=e
|
342
342
|
)
|
343
343
|
except Exception as e:
|
@@ -345,7 +345,7 @@ class DatabaseManager:
|
|
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="DatabaseService.delete_entity",
|
349
349
|
original_error=e
|
350
350
|
)
|
351
351
|
|
@@ -392,7 +392,7 @@ class DatabaseManager:
|
|
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="DatabaseService.soft_delete_entity",
|
396
396
|
original_error=e
|
397
397
|
)
|
398
398
|
except Exception as e:
|
@@ -400,7 +400,7 @@ class DatabaseManager:
|
|
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="DatabaseService.soft_delete_entity",
|
404
404
|
original_error=e
|
405
405
|
)
|
406
406
|
|
@@ -468,14 +468,14 @@ class DatabaseManager:
|
|
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="DatabaseService.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="DatabaseService.list_entities",
|
479
479
|
original_error=e
|
480
480
|
)
|
481
481
|
|
@@ -524,14 +524,14 @@ class DatabaseManager:
|
|
524
524
|
raise CustomException(
|
525
525
|
error_code,
|
526
526
|
detail=detail,
|
527
|
-
source_function="
|
527
|
+
source_function="DatabaseService.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="DatabaseService.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 DatabaseManager:
|
|
539
539
|
raise CustomException(
|
540
540
|
ErrorCode.DB_QUERY_ERROR,
|
541
541
|
detail=str(e),
|
542
|
-
source_function="
|
542
|
+
source_function="DatabaseService.validate_unique_fields",
|
543
543
|
original_error=e
|
544
544
|
)
|
545
545
|
|
@@ -577,7 +577,7 @@ class DatabaseManager:
|
|
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="DatabaseService.validate_foreign_key_fields"
|
581
581
|
)
|
582
582
|
|
583
583
|
#######################
|
@@ -637,7 +637,7 @@ class DatabaseManager:
|
|
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 "DatabaseService.soft_delete"
|
641
641
|
)
|
642
642
|
|
643
643
|
# 2. 소프트 삭제 처리
|
@@ -665,7 +665,7 @@ class DatabaseManager:
|
|
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 "DatabaseService.soft_delete",
|
669
669
|
original_error=e.original_error,
|
670
670
|
parent_source_function=e.source_function
|
671
671
|
)
|
@@ -674,7 +674,7 @@ class DatabaseManager:
|
|
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 "DatabaseService.soft_delete",
|
678
678
|
original_error=e
|
679
679
|
)
|
680
680
|
|
@@ -704,14 +704,14 @@ class DatabaseManager:
|
|
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="DatabaseService.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="DatabaseService.get_entity",
|
715
715
|
original_error=e
|
716
716
|
)
|
717
717
|
|
@@ -757,14 +757,14 @@ class DatabaseManager:
|
|
757
757
|
raise CustomException(
|
758
758
|
ErrorCode.DB_QUERY_ERROR,
|
759
759
|
detail=str(e),
|
760
|
-
source_function="
|
760
|
+
source_function="DatabaseService.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="DatabaseService.execute",
|
768
768
|
original_error=e
|
769
769
|
)
|
770
770
|
|
@@ -777,7 +777,7 @@ class DatabaseManager:
|
|
777
777
|
raise CustomException(
|
778
778
|
ErrorCode.DB_QUERY_ERROR,
|
779
779
|
detail=str(e),
|
780
|
-
source_function="
|
780
|
+
source_function="DatabaseService.commit",
|
781
781
|
original_error=e
|
782
782
|
)
|
783
783
|
|
@@ -789,7 +789,7 @@ class DatabaseManager:
|
|
789
789
|
raise CustomException(
|
790
790
|
ErrorCode.DB_QUERY_ERROR,
|
791
791
|
detail=str(e),
|
792
|
-
source_function="
|
792
|
+
source_function="DatabaseService.rollback",
|
793
793
|
original_error=e
|
794
794
|
)
|
795
795
|
|
@@ -802,7 +802,7 @@ class DatabaseManager:
|
|
802
802
|
raise CustomException(
|
803
803
|
ErrorCode.DB_QUERY_ERROR,
|
804
804
|
detail=str(e),
|
805
|
-
source_function="
|
805
|
+
source_function="DatabaseService.flush",
|
806
806
|
original_error=e
|
807
807
|
)
|
808
808
|
|
@@ -818,6 +818,6 @@ class DatabaseManager:
|
|
818
818
|
raise CustomException(
|
819
819
|
ErrorCode.DB_QUERY_ERROR,
|
820
820
|
detail=str(e),
|
821
|
-
source_function="
|
821
|
+
source_function="DatabaseService.refresh",
|
822
822
|
original_error=e
|
823
823
|
)
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "aiteamutils"
|
7
|
-
|
7
|
+
dynamic = ["version"]
|
8
8
|
authors = [
|
9
9
|
{ name="AI Team" },
|
10
10
|
]
|
@@ -27,5 +27,8 @@ dependencies = [
|
|
27
27
|
Homepage = "https://github.com/yourusername/aiteamutils"
|
28
28
|
Issues = "https://github.com/yourusername/aiteamutils/issues"
|
29
29
|
|
30
|
+
[tool.hatch.version]
|
31
|
+
path = "aiteamutils/version.py"
|
32
|
+
|
30
33
|
[tool.hatch.build.targets.wheel]
|
31
34
|
packages = ["aiteamutils"]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|