xn-model 1.0.24__tar.gz → 1.0.26__tar.gz
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.
- {xn_model-1.0.24/xn_model.egg-info → xn_model-1.0.26}/PKG-INFO +1 -1
- {xn_model-1.0.24 → xn_model-1.0.26}/x_model/__init__.py +3 -2
- {xn_model-1.0.24 → xn_model-1.0.26}/x_model/models.py +14 -8
- {xn_model-1.0.24 → xn_model-1.0.26/xn_model.egg-info}/PKG-INFO +1 -1
- {xn_model-1.0.24 → xn_model-1.0.26}/.env.sample +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/.gitignore +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/.pre-commit-config.yaml +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/README.md +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/makefile +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/pyproject.toml +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/setup.cfg +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/tests/__init__.py +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/tests/test_db.py +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/x_model/field.py +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/x_model/func.py +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/x_model/types.py +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/xn_model.egg-info/SOURCES.txt +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/xn_model.egg-info/dependency_links.txt +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/xn_model.egg-info/requires.txt +0 -0
- {xn_model-1.0.24 → xn_model-1.0.26}/xn_model.egg-info/top_level.txt +0 -0
|
@@ -2,9 +2,10 @@ from tortoise import Tortoise, connections
|
|
|
2
2
|
from tortoise.backends.asyncpg import AsyncpgDBClient
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
async def init_db(conf: dict, create_tables: bool =
|
|
5
|
+
async def init_db(conf: dict, create_tables: bool = False) -> AsyncpgDBClient | str:
|
|
6
6
|
await Tortoise.init(conf)
|
|
7
|
+
cn: AsyncpgDBClient = connections.get("default")
|
|
7
8
|
if create_tables:
|
|
9
|
+
await cn.execute_script("CREATE EXTENSION IF NOT EXISTS uint128;")
|
|
8
10
|
await Tortoise.generate_schemas()
|
|
9
|
-
cn: AsyncpgDBClient = connections.get("default")
|
|
10
11
|
return cn
|
|
@@ -35,8 +35,9 @@ class Model(TortModel):
|
|
|
35
35
|
def in_type(cls, with_pk: bool = False) -> type[BaseUpd]:
|
|
36
36
|
if not getattr(cls, cn := "Upd" if with_pk else "New", None):
|
|
37
37
|
fields: list[tuple[str, type] | tuple[str, type, field]] = []
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
meta = cls._meta
|
|
39
|
+
for fn in meta.db_fields:
|
|
40
|
+
if (f := meta.fields_map[fn]).pk and not with_pk:
|
|
40
41
|
continue
|
|
41
42
|
if getattr(f, "auto_now", None) or getattr(f, "auto_now_add", None):
|
|
42
43
|
continue
|
|
@@ -44,18 +45,23 @@ class Model(TortModel):
|
|
|
44
45
|
if f.default or f.null or (f.allows_generated and not f.pk) or not f.required:
|
|
45
46
|
fld += (field(default_factory=dict) if f.default == {} else field(default=f.default),)
|
|
46
47
|
fields.append(fld)
|
|
47
|
-
# for fn in
|
|
48
|
-
# f =
|
|
48
|
+
# for fn in meta.fk_fields:
|
|
49
|
+
# f = meta.fields_map[fn]
|
|
49
50
|
# fld = fn+"_id", int
|
|
50
51
|
# if f.default or f.allows_generated or f.null or not f.required:
|
|
51
52
|
# fld += (field(default=f.default),)
|
|
52
53
|
# fields.append(fld)
|
|
53
54
|
pre_saves = [f.__name__ for f in cls._listeners[Signals.pre_save].get(cls, [])]
|
|
54
55
|
dcl = make_dataclass(cls.__name__ + cn, fields, bases=(BaseUpd,), kw_only=True)
|
|
55
|
-
dcl._unq = {o + "_id" for o in
|
|
56
|
-
dcl._unq |= set((
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
dcl._unq = {o + "_id" for o in meta.o2o_fields if o not in pre_saves}
|
|
57
|
+
dcl._unq |= set((meta.unique_together or ((),))[0])
|
|
58
|
+
dcl._unq |= {
|
|
59
|
+
k
|
|
60
|
+
for k, f in meta.fields_map.items()
|
|
61
|
+
if f.unique and k not in meta.backward_fk_fields | meta.backward_o2o_fields | meta.m2m_fields
|
|
62
|
+
}
|
|
63
|
+
if not with_pk:
|
|
64
|
+
dcl._unq -= {"id"}
|
|
59
65
|
setattr(cls, cn, dcl)
|
|
60
66
|
|
|
61
67
|
return getattr(cls, cn)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|