xn-model 1.0.1.dev2__tar.gz → 1.0.3__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: xn-model
3
- Version: 1.0.1.dev2
3
+ Version: 1.0.3
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[accel,asyncpg]
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"
@@ -4,7 +4,7 @@ requires-python = ">=3.11"
4
4
  authors = [
5
5
  {name = "Mike Artemiev", email = "mixartemev@gmail.com"},
6
6
  ]
7
- dependencies = ['tortoise-orm[accel,asyncpg]']
7
+ dependencies = ['tortoise-orm[asyncpg]']
8
8
  keywords = ["tortoise", "model", "crud", "generator", "api", "admin"]
9
9
  description = 'Base model for xn-api'
10
10
  readme = "README.md"
@@ -2,21 +2,15 @@ import logging
2
2
  from enum import IntEnum
3
3
  from types import ModuleType
4
4
 
5
- from starlette import status
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
- try:
14
- await Tortoise.init(db_url=dsn, modules={"models": [models]})
15
- if create_tables:
16
- await Tortoise.generate_schemas()
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(BaseHTTPException):
26
+ class HTTPException(Exception):
33
27
  def __init__(
34
28
  self,
35
29
  reason: IntEnum,
36
30
  parent: Exception | str = None,
37
- status_: status = status.HTTP_400_BAD_REQUEST,
31
+ status_: int = 400,
38
32
  hdrs: dict = None,
39
33
  ) -> None:
40
34
  detail = f"{reason.name}{f': {parent}' if parent else ''}"
@@ -21,23 +21,18 @@ class TsTrait:
21
21
  class Model(BaseModel):
22
22
  id: int = IntField(True)
23
23
 
24
+ _pyd: type[PydanticModel] = None
24
25
  _name: tuple[str] = ("name",)
25
26
  _sorts: tuple[str] = ("-id",)
26
27
 
27
28
  def repr(self) -> str:
28
29
  return " ".join(getattr(self, name_fragment) for name_fragment in self._name)
29
30
 
30
- @classmethod
31
- def _pyd(cls, suffix: str, **kwargs) -> type[PydanticModel]:
32
- return pydantic_model_creator(cls, name=cls.__name__ + suffix, **kwargs)
33
-
34
31
  @classmethod
35
32
  def pyd(cls):
36
- return cls._pyd("Root")
37
-
38
- @classmethod
39
- def pyd_in(cls):
40
- return cls._pyd("In", exclude_readonly=True)
33
+ if not cls._pyd:
34
+ cls._pyd = pydantic_model_creator(cls, name=cls.__name__)
35
+ return cls._pyd
41
36
 
42
37
  # # # CRUD Methods # # #
43
38
  @classmethod
@@ -60,7 +55,7 @@ class Model(BaseModel):
60
55
  # exclude: tuple[str, ...] = ("Meta",)
61
56
  # computed: tuple[str, ...] = ()
62
57
  # backward_relations: bool = True
63
- max_recursion: int = 1 # default: 3
58
+ max_recursion: int = 0 # default: 3
64
59
  # allow_cycles: bool = False
65
60
  # exclude_raw_fields: bool = True
66
61
  # sort_alphabetically: bool = False
@@ -1,14 +1,4 @@
1
- # from typing import TypeVar, Generic
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
1
+ Metadata-Version: 2.2
2
2
  Name: xn-model
3
- Version: 1.0.1.dev2
3
+ Version: 1.0.3
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[accel,asyncpg]
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"
@@ -1,4 +1,4 @@
1
- tortoise-orm[accel,asyncpg]
1
+ tortoise-orm[asyncpg]
2
2
 
3
3
  [dev]
4
4
  pytest
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes