async-easy-model 0.2.8__py3-none-any.whl → 0.2.9__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.
- async_easy_model/__init__.py +1 -1
- async_easy_model/model.py +31 -10
- {async_easy_model-0.2.8.dist-info → async_easy_model-0.2.9.dist-info}/METADATA +1 -1
- async_easy_model-0.2.9.dist-info/RECORD +11 -0
- {async_easy_model-0.2.8.dist-info → async_easy_model-0.2.9.dist-info}/WHEEL +1 -1
- async_easy_model-0.2.8.dist-info/RECORD +0 -11
- {async_easy_model-0.2.8.dist-info → async_easy_model-0.2.9.dist-info}/licenses/LICENSE +0 -0
- {async_easy_model-0.2.8.dist-info → async_easy_model-0.2.9.dist-info}/top_level.txt +0 -0
async_easy_model/__init__.py
CHANGED
@@ -12,7 +12,7 @@ from typing import Optional, Any
|
|
12
12
|
from .model import EasyModel, init_db, db_config
|
13
13
|
from sqlmodel import Field, Relationship as SQLModelRelationship
|
14
14
|
|
15
|
-
__version__ = "0.2.
|
15
|
+
__version__ = "0.2.9"
|
16
16
|
__all__ = ["EasyModel", "init_db", "db_config", "Field", "Relationship", "Relation", "enable_auto_relationships", "disable_auto_relationships", "process_auto_relationships", "MigrationManager", "check_and_migrate_models", "ModelVisualizer"]
|
17
17
|
|
18
18
|
# Create a more user-friendly Relationship function
|
async_easy_model/model.py
CHANGED
@@ -73,15 +73,21 @@ class DatabaseConfig:
|
|
73
73
|
def get_engine(self):
|
74
74
|
"""Get or create the SQLAlchemy engine."""
|
75
75
|
if DatabaseConfig._engine is None:
|
76
|
-
|
76
|
+
# Apply connection pool configuration to all database types
|
77
|
+
# to prevent connection leaks and ensure proper resource management
|
78
|
+
kwargs = {
|
79
|
+
"pool_size": 10, # Base number of connections in the pool
|
80
|
+
"max_overflow": 30, # Additional connections allowed beyond pool_size
|
81
|
+
"pool_timeout": 30, # Timeout in seconds for getting connection from pool
|
82
|
+
"pool_recycle": 1800, # Recycle connections after 30 minutes
|
83
|
+
"pool_pre_ping": True, # Verify connections before use
|
84
|
+
}
|
85
|
+
|
86
|
+
# PostgreSQL-specific optimizations (if needed in the future)
|
77
87
|
if self.db_type == "postgresql":
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
"pool_timeout": 30,
|
82
|
-
"pool_recycle": 1800,
|
83
|
-
"pool_pre_ping": True,
|
84
|
-
})
|
88
|
+
# PostgreSQL already has good defaults above
|
89
|
+
pass
|
90
|
+
|
85
91
|
DatabaseConfig._engine = create_async_engine(
|
86
92
|
self.get_connection_url(),
|
87
93
|
**kwargs
|
@@ -115,9 +121,24 @@ class EasyModel(SQLModel):
|
|
115
121
|
@classmethod
|
116
122
|
@contextlib.asynccontextmanager
|
117
123
|
async def get_session(cls):
|
118
|
-
"""Provide a transactional scope for database operations.
|
119
|
-
|
124
|
+
"""Provide a transactional scope for database operations.
|
125
|
+
|
126
|
+
This method ensures proper session cleanup by:
|
127
|
+
- Explicitly rolling back transactions on exceptions
|
128
|
+
- Explicitly closing sessions in all cases
|
129
|
+
- Proper exception propagation
|
130
|
+
"""
|
131
|
+
session = None
|
132
|
+
try:
|
133
|
+
session = db_config.get_session_maker()()
|
120
134
|
yield session
|
135
|
+
except Exception:
|
136
|
+
if session:
|
137
|
+
await session.rollback()
|
138
|
+
raise
|
139
|
+
finally:
|
140
|
+
if session:
|
141
|
+
await session.close()
|
121
142
|
|
122
143
|
@classmethod
|
123
144
|
def _get_relationship_fields(cls) -> List[str]:
|
@@ -0,0 +1,11 @@
|
|
1
|
+
async_easy_model/__init__.py,sha256=eGTq3OypupyVvLe2Zyn3ZFBeuU4v8EXW-XQ047vUMoM,1921
|
2
|
+
async_easy_model/auto_relationships.py,sha256=V2LAzNi7y-keFk4C_m-byVRM-k_7nL5HEy9Ig3nEdq8,27756
|
3
|
+
async_easy_model/migrations.py,sha256=rYDGCGlruSugAmPfdIF2-uhyG6UvC_2qbF3BXJ084qI,17803
|
4
|
+
async_easy_model/model.py,sha256=pBWRAVhazZuI_rBOnILPttiCF_ZEomWBJGDmfdFp8Nk,64243
|
5
|
+
async_easy_model/relationships.py,sha256=vR5BsJpGaDcecCcNlg9-ouZfxFXFQv5kOyiXhKp_T7A,3286
|
6
|
+
async_easy_model/visualization.py,sha256=RVCdc8j3uUQe-zy3jXju_yhA13qJ8KWVbQ5fQyjyqkA,29973
|
7
|
+
async_easy_model-0.2.9.dist-info/licenses/LICENSE,sha256=uwDkl6oHbRltW7vYKNc4doJyhtwhyrSNFFlPpKATwLE,1072
|
8
|
+
async_easy_model-0.2.9.dist-info/METADATA,sha256=iVRM1qe6DfdFUSa5FYYES-oXgkKScm7m2BVClhlH-k8,12888
|
9
|
+
async_easy_model-0.2.9.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
10
|
+
async_easy_model-0.2.9.dist-info/top_level.txt,sha256=e5_47sGmJnyxz2msfwU6C316EqmrSd9RGIYwZyWx68E,17
|
11
|
+
async_easy_model-0.2.9.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
async_easy_model/__init__.py,sha256=8wTdiTMrhwZjclRALXktyRIBJ4ONt-F0JG_CK60yz9A,1921
|
2
|
-
async_easy_model/auto_relationships.py,sha256=V2LAzNi7y-keFk4C_m-byVRM-k_7nL5HEy9Ig3nEdq8,27756
|
3
|
-
async_easy_model/migrations.py,sha256=rYDGCGlruSugAmPfdIF2-uhyG6UvC_2qbF3BXJ084qI,17803
|
4
|
-
async_easy_model/model.py,sha256=f0eMcIaDOz9s01A4jpQ-T_VpCgFt67JF1puDYuhpdv4,63290
|
5
|
-
async_easy_model/relationships.py,sha256=vR5BsJpGaDcecCcNlg9-ouZfxFXFQv5kOyiXhKp_T7A,3286
|
6
|
-
async_easy_model/visualization.py,sha256=RVCdc8j3uUQe-zy3jXju_yhA13qJ8KWVbQ5fQyjyqkA,29973
|
7
|
-
async_easy_model-0.2.8.dist-info/licenses/LICENSE,sha256=uwDkl6oHbRltW7vYKNc4doJyhtwhyrSNFFlPpKATwLE,1072
|
8
|
-
async_easy_model-0.2.8.dist-info/METADATA,sha256=29ESU7RvrK94YP0v2iwy_v8f06nFLs96D3hPJJibO1U,12888
|
9
|
-
async_easy_model-0.2.8.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
|
10
|
-
async_easy_model-0.2.8.dist-info/top_level.txt,sha256=e5_47sGmJnyxz2msfwU6C316EqmrSd9RGIYwZyWx68E,17
|
11
|
-
async_easy_model-0.2.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|