xn-model 1.0.21__py3-none-any.whl → 1.0.23__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/field.py CHANGED
@@ -4,7 +4,7 @@ from typing import Any
4
4
  from asyncpg import Range, Point # Box, Polygon,
5
5
  from tortoise import Model
6
6
  from tortoise.contrib.postgres.fields import ArrayField
7
- from tortoise.fields import Field, SmallIntField, IntField, FloatField, DatetimeField, BinaryField, BigIntField
7
+ from tortoise.fields import Field, SmallIntField, IntField, FloatField, DatetimeField, BinaryField
8
8
  from tortoise.fields.base import VALUE
9
9
 
10
10
 
@@ -12,8 +12,20 @@ class UniqBinaryField(BinaryField):
12
12
  indexable = True
13
13
 
14
14
 
15
- class UInt1Field(IntField):
16
- SQL_TYPE = "UINT2"
15
+ class UIntField(IntField):
16
+ def to_db_value(self, value: Any, instance: type[Model] | Model) -> Any:
17
+ self.validate(value)
18
+ return value if value is None or isinstance(value, str) else str(value)
19
+
20
+ def to_python_value(self, value: Any) -> Any:
21
+ return value if value is None or isinstance(value, int) else int(value)
22
+
23
+
24
+ class UInt1Field(UIntField):
25
+ SQL_TYPE = "UINT1"
26
+
27
+ class _db_postgres:
28
+ GENERATED_SQL = "UINT1 NOT NULL PRIMARY KEY"
17
29
 
18
30
  @property
19
31
  def constraints(self) -> dict:
@@ -23,9 +35,12 @@ class UInt1Field(IntField):
23
35
  }
24
36
 
25
37
 
26
- class UInt2Field(IntField):
38
+ class UInt2Field(UIntField):
27
39
  SQL_TYPE = "UINT2"
28
40
 
41
+ class _db_postgres:
42
+ GENERATED_SQL = "UINT2 NOT NULL PRIMARY KEY"
43
+
29
44
  @property
30
45
  def constraints(self) -> dict:
31
46
  return {
@@ -34,9 +49,12 @@ class UInt2Field(IntField):
34
49
  }
35
50
 
36
51
 
37
- class UIntField(IntField):
52
+ class UInt4Field(UIntField):
38
53
  SQL_TYPE = "UINT4"
39
54
 
55
+ class _db_postgres:
56
+ GENERATED_SQL = "UINT4 NOT NULL PRIMARY KEY"
57
+
40
58
  @property
41
59
  def constraints(self) -> dict:
42
60
  return {
@@ -45,9 +63,12 @@ class UIntField(IntField):
45
63
  }
46
64
 
47
65
 
48
- class UInt8Field(BigIntField):
66
+ class UInt8Field(UIntField):
49
67
  SQL_TYPE = "UINT8"
50
68
 
69
+ class _db_postgres:
70
+ GENERATED_SQL = "UINT8 NOT NULL PRIMARY KEY"
71
+
51
72
  @property
52
73
  def constraints(self) -> dict:
53
74
  return {
@@ -56,9 +77,12 @@ class UInt8Field(BigIntField):
56
77
  }
57
78
 
58
79
 
59
- class UInt16Field(BigIntField):
80
+ class UInt16Field(UIntField):
60
81
  SQL_TYPE = "UINT16"
61
82
 
83
+ class _db_postgres:
84
+ GENERATED_SQL = "UINT16 NOT NULL PRIMARY KEY"
85
+
62
86
  @property
63
87
  def constraints(self) -> dict:
64
88
  return {
x_model/models.py CHANGED
@@ -6,7 +6,7 @@ from pydantic import ConfigDict
6
6
  from tortoise import Model as TortModel
7
7
  from tortoise.signals import Signals
8
8
 
9
- from x_model.field import DatetimeSecField, UIntField
9
+ from x_model.field import DatetimeSecField, IntField
10
10
  from x_model.types import BaseUpd
11
11
 
12
12
 
@@ -16,7 +16,7 @@ class TsTrait:
16
16
 
17
17
 
18
18
  class Model(TortModel):
19
- id: int = UIntField(True)
19
+ id: int = IntField(True)
20
20
 
21
21
  _in_type: type[BaseUpd] = None # overridable
22
22
  _name: tuple[str] = ("name",)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xn-model
3
- Version: 1.0.21
3
+ Version: 1.0.23
4
4
  Summary: Base model for xn-api
5
5
  Author-email: Mike Artemiev <mixartemev@gmail.com>
6
6
  License: MIT
@@ -0,0 +1,9 @@
1
+ x_model/__init__.py,sha256=1Lgvr-SZwkM4R7L0ceVLyArzzMJiFLgaid-RUOk_ypM,344
2
+ x_model/field.py,sha256=Qf2nua1Qj_6OAtjLCCxC5h9dtEGNOWIA-Z8est_BoKY,4533
3
+ x_model/func.py,sha256=flj89sCOou7NJlriPYbIpX8rdbugbe-vjT2C0ORl9DY,312
4
+ x_model/models.py,sha256=apHNmhnzjjJ9ATUxSSdei7uixEUrNzc2PcwJhN4rayM,3791
5
+ x_model/types.py,sha256=CITb6DSLZ3KHmEgQRjZCFRUId4x-_pecwZdh6xXt0HE,339
6
+ xn_model-1.0.23.dist-info/METADATA,sha256=bCfadu4c_mKcDPS3K4R_j4eKEjFn8BPnPvnqbrUWpCw,986
7
+ xn_model-1.0.23.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ xn_model-1.0.23.dist-info/top_level.txt,sha256=QCYyfv5AA_8jPPtCpShkBXzQRUCGuuW7Ro0mqysDE8E,8
9
+ xn_model-1.0.23.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- x_model/__init__.py,sha256=1Lgvr-SZwkM4R7L0ceVLyArzzMJiFLgaid-RUOk_ypM,344
2
- x_model/field.py,sha256=1PzHWYodsjx5waC9aH07faAC4WBrEhpWgXL39SyKYQU,3809
3
- x_model/func.py,sha256=flj89sCOou7NJlriPYbIpX8rdbugbe-vjT2C0ORl9DY,312
4
- x_model/models.py,sha256=Pdkcemb2jSFU0x7YSz9nWVmoGyShF-TzAo2SOUjVbvM,3793
5
- x_model/types.py,sha256=CITb6DSLZ3KHmEgQRjZCFRUId4x-_pecwZdh6xXt0HE,339
6
- xn_model-1.0.21.dist-info/METADATA,sha256=EIxiWmHURXnDjfMNcdah-x2-P9segJeggINIK7-IBTA,986
7
- xn_model-1.0.21.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- xn_model-1.0.21.dist-info/top_level.txt,sha256=QCYyfv5AA_8jPPtCpShkBXzQRUCGuuW7Ro0mqysDE8E,8
9
- xn_model-1.0.21.dist-info/RECORD,,