xn-model 1.0.1.dev2__py3-none-any.whl → 1.0.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.
- x_model/__init__.py +7 -13
- x_model/models.py +2 -10
- x_model/pydantic.py +1 -11
- {xn_model-1.0.1.dev2.dist-info → xn_model-1.0.2.dist-info}/METADATA +3 -3
- xn_model-1.0.2.dist-info/RECORD +9 -0
- {xn_model-1.0.1.dev2.dist-info → xn_model-1.0.2.dist-info}/WHEEL +1 -1
- xn_model-1.0.1.dev2.dist-info/RECORD +0 -9
- {xn_model-1.0.1.dev2.dist-info → xn_model-1.0.2.dist-info}/top_level.txt +0 -0
x_model/__init__.py
CHANGED
|
@@ -2,21 +2,15 @@ import logging
|
|
|
2
2
|
from enum import IntEnum
|
|
3
3
|
from types import ModuleType
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
from tortoise import Tortoise, connections, ConfigurationError
|
|
5
|
+
from tortoise import Tortoise, connections
|
|
7
6
|
from tortoise.backends.asyncpg import AsyncpgDBClient
|
|
8
|
-
from tortoise.exceptions import DBConnectionError
|
|
9
|
-
from fastapi import HTTPException as BaseHTTPException
|
|
10
7
|
|
|
11
8
|
|
|
12
9
|
async def init_db(dsn: str, models: ModuleType, create_tables: bool = False) -> AsyncpgDBClient | str:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
cn: AsyncpgDBClient = connections.get("default")
|
|
18
|
-
except (ConfigurationError, DBConnectionError) as ce:
|
|
19
|
-
return ce.args[0]
|
|
10
|
+
await Tortoise.init(db_url=dsn, modules={"models": [models]})
|
|
11
|
+
if create_tables:
|
|
12
|
+
await Tortoise.generate_schemas()
|
|
13
|
+
cn: AsyncpgDBClient = connections.get("default")
|
|
20
14
|
return cn
|
|
21
15
|
|
|
22
16
|
|
|
@@ -29,12 +23,12 @@ class FailReason(IntEnum):
|
|
|
29
23
|
method = 13
|
|
30
24
|
|
|
31
25
|
|
|
32
|
-
class HTTPException(
|
|
26
|
+
class HTTPException(Exception):
|
|
33
27
|
def __init__(
|
|
34
28
|
self,
|
|
35
29
|
reason: IntEnum,
|
|
36
30
|
parent: Exception | str = None,
|
|
37
|
-
status_:
|
|
31
|
+
status_: int = 400,
|
|
38
32
|
hdrs: dict = None,
|
|
39
33
|
) -> None:
|
|
40
34
|
detail = f"{reason.name}{f': {parent}' if parent else ''}"
|
x_model/models.py
CHANGED
|
@@ -27,17 +27,9 @@ class Model(BaseModel):
|
|
|
27
27
|
def repr(self) -> str:
|
|
28
28
|
return " ".join(getattr(self, name_fragment) for name_fragment in self._name)
|
|
29
29
|
|
|
30
|
-
@classmethod
|
|
31
|
-
def _pyd(cls, suffix: str, **kwargs) -> type[PydanticModel]:
|
|
32
|
-
return pydantic_model_creator(cls, name=cls.__name__ + suffix, **kwargs)
|
|
33
|
-
|
|
34
30
|
@classmethod
|
|
35
31
|
def pyd(cls):
|
|
36
|
-
return cls.
|
|
37
|
-
|
|
38
|
-
@classmethod
|
|
39
|
-
def pyd_in(cls):
|
|
40
|
-
return cls._pyd("In", exclude_readonly=True)
|
|
32
|
+
return pydantic_model_creator(cls, name=cls.__name__)
|
|
41
33
|
|
|
42
34
|
# # # CRUD Methods # # #
|
|
43
35
|
@classmethod
|
|
@@ -60,7 +52,7 @@ class Model(BaseModel):
|
|
|
60
52
|
# exclude: tuple[str, ...] = ("Meta",)
|
|
61
53
|
# computed: tuple[str, ...] = ()
|
|
62
54
|
# backward_relations: bool = True
|
|
63
|
-
max_recursion: int =
|
|
55
|
+
max_recursion: int = 0 # default: 3
|
|
64
56
|
# allow_cycles: bool = False
|
|
65
57
|
# exclude_raw_fields: bool = True
|
|
66
58
|
# sort_alphabetically: bool = False
|
x_model/pydantic.py
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
from pydantic import BaseModel # , ConfigDict
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# RootModelType = TypeVar("RootModelType")
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
# class PydList(BaseModel, Generic[RootModelType]):
|
|
9
|
-
# model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
10
|
-
# data: list[RootModelType]
|
|
11
|
-
# total: int
|
|
1
|
+
from pydantic import BaseModel
|
|
12
2
|
|
|
13
3
|
|
|
14
4
|
class Names(BaseModel):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: xn-model
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: Base model for xn-api
|
|
5
5
|
Author-email: Mike Artemiev <mixartemev@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -9,7 +9,7 @@ Project-URL: Repository, https://github.com/XyncNet/x-model
|
|
|
9
9
|
Keywords: tortoise,model,crud,generator,api,admin
|
|
10
10
|
Requires-Python: >=3.11
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
|
-
Requires-Dist: tortoise-orm[
|
|
12
|
+
Requires-Dist: tortoise-orm[asyncpg]
|
|
13
13
|
Provides-Extra: dev
|
|
14
14
|
Requires-Dist: pytest; extra == "dev"
|
|
15
15
|
Requires-Dist: python-dotenv; extra == "dev"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
x_model/__init__.py,sha256=JgpONZwWeYiV4mzk0nT8PM4ZzTSCSAGy4PV2G2ZIW04,933
|
|
2
|
+
x_model/field.py,sha256=S461M94ryQG7yu8lreXtWnZo3YdCP97xhbcCJ3BzXsY,2751
|
|
3
|
+
x_model/func.py,sha256=E7jDoHJGaFpKvxbHnT_lyBxUZeMo-GRd5gv9dLw7B9s,289
|
|
4
|
+
x_model/models.py,sha256=XZu7jWf0Wl5JiHvS222iumMk3eJLuQBkhOVfq-46qd8,2141
|
|
5
|
+
x_model/pydantic.py,sha256=18O4yFvYDyZaSqIaOKcZhQRpIBM2o73DNlqrXvU_4XM,342
|
|
6
|
+
xn_model-1.0.2.dist-info/METADATA,sha256=0B-FErvCVRVC13r_j1TMqZrcQ6KssyvNoO6OlsnArsw,961
|
|
7
|
+
xn_model-1.0.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
8
|
+
xn_model-1.0.2.dist-info/top_level.txt,sha256=QCYyfv5AA_8jPPtCpShkBXzQRUCGuuW7Ro0mqysDE8E,8
|
|
9
|
+
xn_model-1.0.2.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
x_model/__init__.py,sha256=leq1K2Lq0zlTY2s5sdhDiGEyfNZPySCOJi0xB5xUSG0,1231
|
|
2
|
-
x_model/field.py,sha256=S461M94ryQG7yu8lreXtWnZo3YdCP97xhbcCJ3BzXsY,2751
|
|
3
|
-
x_model/func.py,sha256=E7jDoHJGaFpKvxbHnT_lyBxUZeMo-GRd5gv9dLw7B9s,289
|
|
4
|
-
x_model/models.py,sha256=3ygo54HJTpHiD65Rgdzy5BNWJjtZiyypGiRlbDQ3oRc,2367
|
|
5
|
-
x_model/pydantic.py,sha256=fe8yOCVlnlBcT64bhNodxegnA6f4YdJ0WcXDIs6Ug20,608
|
|
6
|
-
xn_model-1.0.1.dev2.dist-info/METADATA,sha256=J4VHD6RXpem2cdyTQ-XlUr4j1y_ZDzjVKr5-EKUrYmY,972
|
|
7
|
-
xn_model-1.0.1.dev2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
8
|
-
xn_model-1.0.1.dev2.dist-info/top_level.txt,sha256=QCYyfv5AA_8jPPtCpShkBXzQRUCGuuW7Ro0mqysDE8E,8
|
|
9
|
-
xn_model-1.0.1.dev2.dist-info/RECORD,,
|
|
File without changes
|