async-easy-model 0.3.0__py3-none-any.whl → 0.3.1__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/auto_relationships.py +6 -6
- async_easy_model/migrations.py +17 -1
- async_easy_model/model.py +3 -3
- async_easy_model/visualization.py +3 -3
- {async_easy_model-0.3.0.dist-info → async_easy_model-0.3.1.dist-info}/METADATA +1 -1
- async_easy_model-0.3.1.dist-info/RECORD +11 -0
- async_easy_model-0.3.0.dist-info/RECORD +0 -11
- {async_easy_model-0.3.0.dist-info → async_easy_model-0.3.1.dist-info}/WHEEL +0 -0
- {async_easy_model-0.3.0.dist-info → async_easy_model-0.3.1.dist-info}/licenses/LICENSE +0 -0
- {async_easy_model-0.3.0.dist-info → async_easy_model-0.3.1.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.3.
|
15
|
+
__version__ = "0.3.1"
|
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
|
@@ -119,10 +119,10 @@ def get_foreign_keys_from_model(model_cls: Type[SQLModel]) -> Dict[str, str]:
|
|
119
119
|
|
120
120
|
foreign_keys = {}
|
121
121
|
|
122
|
-
# First method: Check SQLModel's
|
123
|
-
if hasattr(model_cls, "
|
124
|
-
logger.info(f"Using
|
125
|
-
for field_name, field_info in model_cls.
|
122
|
+
# First method: Check SQLModel's model_fields dictionary (Pydantic V2)
|
123
|
+
if hasattr(model_cls, "model_fields"):
|
124
|
+
logger.info(f"Using model_fields to find foreign keys in {model_cls.__name__}")
|
125
|
+
for field_name, field_info in model_cls.model_fields.items():
|
126
126
|
# Check if the field has a foreign_key attribute
|
127
127
|
if hasattr(field_info, "foreign_key") and field_info.foreign_key:
|
128
128
|
foreign_key = field_info.foreign_key
|
@@ -156,7 +156,7 @@ def get_foreign_keys_from_model(model_cls: Type[SQLModel]) -> Dict[str, str]:
|
|
156
156
|
# Second method: Try to infer foreign keys from field names
|
157
157
|
if not foreign_keys:
|
158
158
|
logger.info(f"No foreign keys found in model {model_cls.__name__} metadata, trying to detect from field names")
|
159
|
-
for field_name in getattr(model_cls, "
|
159
|
+
for field_name in getattr(model_cls, "model_fields", {}):
|
160
160
|
if field_name.endswith("_id"):
|
161
161
|
# Infer the referenced model from the field name
|
162
162
|
model_name = field_name[:-3] # Remove _id suffix
|
@@ -593,7 +593,7 @@ def is_junction_table(model_cls: Type[SQLModel]) -> bool:
|
|
593
593
|
|
594
594
|
# Check if all non-standard fields are foreign keys
|
595
595
|
standard_fields = {'id', 'created_at', 'updated_at'}
|
596
|
-
model_fields = set(getattr(model_cls, '
|
596
|
+
model_fields = set(getattr(model_cls, 'model_fields', {}).keys())
|
597
597
|
non_standard_fields = model_fields - standard_fields
|
598
598
|
foreign_key_fields = set(foreign_keys.keys())
|
599
599
|
|
async_easy_model/migrations.py
CHANGED
@@ -64,10 +64,26 @@ async def _create_table_without_indexes(table, connection):
|
|
64
64
|
"""
|
65
65
|
# Create a copy of the table without indexes
|
66
66
|
metadata = MetaData()
|
67
|
+
# Manually create columns instead of using deprecated copy() method
|
68
|
+
new_columns = []
|
69
|
+
for col in table.columns:
|
70
|
+
new_col = Column(
|
71
|
+
col.name,
|
72
|
+
col.type,
|
73
|
+
nullable=col.nullable,
|
74
|
+
default=col.default,
|
75
|
+
server_default=col.server_default,
|
76
|
+
primary_key=col.primary_key,
|
77
|
+
unique=col.unique,
|
78
|
+
autoincrement=col.autoincrement,
|
79
|
+
comment=col.comment
|
80
|
+
)
|
81
|
+
new_columns.append(new_col)
|
82
|
+
|
67
83
|
new_table = Table(
|
68
84
|
table.name,
|
69
85
|
metadata,
|
70
|
-
*
|
86
|
+
*new_columns,
|
71
87
|
schema=table.schema
|
72
88
|
)
|
73
89
|
|
async_easy_model/model.py
CHANGED
@@ -395,7 +395,7 @@ class EasyModel(SQLModel):
|
|
395
395
|
List of field names that have unique constraints
|
396
396
|
"""
|
397
397
|
unique_fields = []
|
398
|
-
for name, field in cls.
|
398
|
+
for name, field in cls.model_fields.items():
|
399
399
|
if name != 'id' and hasattr(field, "field_info") and field.field_info.extra.get('unique', False):
|
400
400
|
unique_fields.append(name)
|
401
401
|
return unique_fields
|
@@ -676,7 +676,7 @@ class EasyModel(SQLModel):
|
|
676
676
|
"""
|
677
677
|
# Look for unique fields in the related model to use for searching
|
678
678
|
unique_fields = []
|
679
|
-
for name, field in related_model.
|
679
|
+
for name, field in related_model.model_fields.items():
|
680
680
|
if (hasattr(field, "field_info") and
|
681
681
|
field.field_info.extra.get('unique', False)):
|
682
682
|
unique_fields.append(name)
|
@@ -822,7 +822,7 @@ class EasyModel(SQLModel):
|
|
822
822
|
# Check for unique constraints before updating
|
823
823
|
for field_name, new_value in data.items():
|
824
824
|
if field_name != 'id' and hasattr(cls, field_name):
|
825
|
-
field = getattr(cls.
|
825
|
+
field = getattr(cls.model_fields.get(field_name), 'field_info', None)
|
826
826
|
if field and field.extra.get('unique', False):
|
827
827
|
# Check if the new value would conflict with an existing record
|
828
828
|
check_statement = select(cls).where(
|
@@ -80,7 +80,7 @@ class ModelVisualizer:
|
|
80
80
|
foreign_keys = {}
|
81
81
|
|
82
82
|
try:
|
83
|
-
# Check model annotations and
|
83
|
+
# Check model annotations and model_fields for foreign keys
|
84
84
|
if hasattr(model_class, "__annotations__"):
|
85
85
|
for field_name, field_type in model_class.__annotations__.items():
|
86
86
|
if hasattr(model_class, field_name):
|
@@ -102,8 +102,8 @@ class ModelVisualizer:
|
|
102
102
|
pass
|
103
103
|
|
104
104
|
# Try to infer foreign keys from field names ending with _id
|
105
|
-
if hasattr(model_class, "
|
106
|
-
for field_name in model_class.
|
105
|
+
if hasattr(model_class, "model_fields"):
|
106
|
+
for field_name in model_class.model_fields:
|
107
107
|
if field_name.endswith("_id") and field_name not in foreign_keys:
|
108
108
|
related_name = field_name[:-3] # Remove _id suffix
|
109
109
|
# Check if there's a model with this name
|
@@ -0,0 +1,11 @@
|
|
1
|
+
async_easy_model/__init__.py,sha256=jZ6t8zToAbMXdEbFcOh15WlOa9uHYrO4QmoqxuZImCI,1921
|
2
|
+
async_easy_model/auto_relationships.py,sha256=ZYM3IdNBLJ5Q0jz9W9UuL379m0Y3ZVOCbngz0Xa2I_U,27782
|
3
|
+
async_easy_model/migrations.py,sha256=o0q2LjzGE8abjjpWDpB7G6EJt-nZOQ_oM2lm56GvS0E,18289
|
4
|
+
async_easy_model/model.py,sha256=FviTK-RQ0GMCQNiR8G1cACcrSY1jQMl7bPEg1mcD5WI,66514
|
5
|
+
async_easy_model/relationships.py,sha256=vR5BsJpGaDcecCcNlg9-ouZfxFXFQv5kOyiXhKp_T7A,3286
|
6
|
+
async_easy_model/visualization.py,sha256=rL3J_KhstR3UI-DxIvyjaDd60YueCnlfG_7E2Cf9i_E,29979
|
7
|
+
async_easy_model-0.3.1.dist-info/licenses/LICENSE,sha256=uwDkl6oHbRltW7vYKNc4doJyhtwhyrSNFFlPpKATwLE,1072
|
8
|
+
async_easy_model-0.3.1.dist-info/METADATA,sha256=YKgL1jBWsxPh7JrlKwhUOb0Jm-N-3kQaxtoO44Gtfus,13047
|
9
|
+
async_easy_model-0.3.1.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
10
|
+
async_easy_model-0.3.1.dist-info/top_level.txt,sha256=e5_47sGmJnyxz2msfwU6C316EqmrSd9RGIYwZyWx68E,17
|
11
|
+
async_easy_model-0.3.1.dist-info/RECORD,,
|
@@ -1,11 +0,0 @@
|
|
1
|
-
async_easy_model/__init__.py,sha256=IXheLaQx-dpGPL6oBEaaIftZDihlFB7bwzEWfMlZ4Ts,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=XxlFOYiX8HT1B6PBB3RubuvB5j4aYKEyO-sPA202Y2U,66508
|
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.3.0.dist-info/licenses/LICENSE,sha256=uwDkl6oHbRltW7vYKNc4doJyhtwhyrSNFFlPpKATwLE,1072
|
8
|
-
async_easy_model-0.3.0.dist-info/METADATA,sha256=0PEppZL9WiSl1uKDqlC-f-l9rrrM-x5HVcRWBcRgsJU,13047
|
9
|
-
async_easy_model-0.3.0.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
10
|
-
async_easy_model-0.3.0.dist-info/top_level.txt,sha256=e5_47sGmJnyxz2msfwU6C316EqmrSd9RGIYwZyWx68E,17
|
11
|
-
async_easy_model-0.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|