ormlambda 2.11.1__py3-none-any.whl → 3.7.0__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.
Files changed (119) hide show
  1. ormlambda/__init__.py +11 -9
  2. ormlambda/caster/__init__.py +3 -0
  3. ormlambda/caster/base_caster.py +69 -0
  4. ormlambda/caster/caster.py +48 -0
  5. ormlambda/caster/interfaces/ICaster.py +26 -0
  6. ormlambda/caster/interfaces/__init__.py +1 -0
  7. ormlambda/common/__init__.py +1 -1
  8. ormlambda/common/abstract_classes/__init__.py +3 -3
  9. ormlambda/common/abstract_classes/decomposition_query.py +117 -315
  10. ormlambda/common/abstract_classes/non_query_base.py +1 -1
  11. ormlambda/common/enums/condition_types.py +2 -1
  12. ormlambda/common/enums/join_type.py +4 -1
  13. ormlambda/common/errors/__init__.py +15 -2
  14. ormlambda/common/global_checker.py +28 -0
  15. ormlambda/common/interfaces/ICustomAlias.py +4 -1
  16. ormlambda/common/interfaces/IDecompositionQuery.py +9 -34
  17. ormlambda/common/interfaces/IJoinSelector.py +21 -0
  18. ormlambda/common/interfaces/__init__.py +4 -6
  19. ormlambda/components/__init__.py +4 -0
  20. ormlambda/components/insert/abstract_insert.py +1 -1
  21. ormlambda/components/select/ISelect.py +17 -0
  22. ormlambda/components/select/__init__.py +1 -0
  23. ormlambda/components/update/abstract_update.py +4 -4
  24. ormlambda/components/upsert/abstract_upsert.py +1 -1
  25. ormlambda/databases/__init__.py +5 -0
  26. ormlambda/databases/my_sql/__init__.py +3 -1
  27. ormlambda/databases/my_sql/caster/__init__.py +1 -0
  28. ormlambda/databases/my_sql/caster/caster.py +38 -0
  29. ormlambda/databases/my_sql/caster/read.py +39 -0
  30. ormlambda/databases/my_sql/caster/types/__init__.py +8 -0
  31. ormlambda/databases/my_sql/caster/types/bytes.py +31 -0
  32. ormlambda/databases/my_sql/caster/types/datetime.py +34 -0
  33. ormlambda/databases/my_sql/caster/types/float.py +31 -0
  34. ormlambda/databases/my_sql/caster/types/int.py +31 -0
  35. ormlambda/databases/my_sql/caster/types/iterable.py +31 -0
  36. ormlambda/databases/my_sql/caster/types/none.py +30 -0
  37. ormlambda/databases/my_sql/caster/types/point.py +43 -0
  38. ormlambda/databases/my_sql/caster/types/string.py +31 -0
  39. ormlambda/databases/my_sql/caster/write.py +37 -0
  40. ormlambda/databases/my_sql/clauses/ST_AsText.py +36 -0
  41. ormlambda/databases/my_sql/clauses/ST_Contains.py +31 -0
  42. ormlambda/databases/my_sql/clauses/__init__.py +6 -4
  43. ormlambda/databases/my_sql/clauses/alias.py +24 -21
  44. ormlambda/databases/my_sql/clauses/count.py +32 -28
  45. ormlambda/databases/my_sql/clauses/create_database.py +3 -4
  46. ormlambda/databases/my_sql/clauses/delete.py +10 -10
  47. ormlambda/databases/my_sql/clauses/drop_database.py +3 -5
  48. ormlambda/databases/my_sql/clauses/drop_table.py +3 -3
  49. ormlambda/databases/my_sql/clauses/group_by.py +4 -7
  50. ormlambda/databases/my_sql/clauses/insert.py +33 -19
  51. ormlambda/databases/my_sql/clauses/joins.py +66 -59
  52. ormlambda/databases/my_sql/clauses/limit.py +1 -1
  53. ormlambda/databases/my_sql/clauses/offset.py +1 -1
  54. ormlambda/databases/my_sql/clauses/order.py +36 -23
  55. ormlambda/databases/my_sql/clauses/select.py +25 -36
  56. ormlambda/databases/my_sql/clauses/update.py +38 -13
  57. ormlambda/databases/my_sql/clauses/upsert.py +2 -2
  58. ormlambda/databases/my_sql/clauses/where.py +45 -0
  59. ormlambda/databases/my_sql/functions/concat.py +24 -27
  60. ormlambda/databases/my_sql/functions/max.py +32 -28
  61. ormlambda/databases/my_sql/functions/min.py +32 -28
  62. ormlambda/databases/my_sql/functions/sum.py +32 -28
  63. ormlambda/databases/my_sql/join_context.py +75 -0
  64. ormlambda/databases/my_sql/repository/__init__.py +1 -0
  65. ormlambda/databases/my_sql/{repository.py → repository/repository.py} +104 -73
  66. ormlambda/databases/my_sql/statements.py +231 -153
  67. ormlambda/engine/__init__.py +0 -0
  68. ormlambda/engine/template.py +47 -0
  69. ormlambda/model/__init__.py +0 -0
  70. ormlambda/model/base_model.py +37 -0
  71. ormlambda/repository/__init__.py +2 -0
  72. ormlambda/repository/base_repository.py +14 -0
  73. ormlambda/repository/interfaces/IDatabaseConnection.py +12 -0
  74. ormlambda/{common → repository}/interfaces/IRepositoryBase.py +6 -5
  75. ormlambda/repository/interfaces/__init__.py +2 -0
  76. ormlambda/sql/__init__.py +3 -0
  77. ormlambda/sql/clause_info/__init__.py +3 -0
  78. ormlambda/sql/clause_info/clause_info.py +434 -0
  79. ormlambda/sql/clause_info/clause_info_context.py +87 -0
  80. ormlambda/sql/clause_info/interface/IAggregate.py +10 -0
  81. ormlambda/sql/clause_info/interface/__init__.py +1 -0
  82. ormlambda/sql/column.py +126 -0
  83. ormlambda/sql/comparer.py +156 -0
  84. ormlambda/sql/foreign_key.py +115 -0
  85. ormlambda/sql/interfaces/__init__.py +0 -0
  86. ormlambda/sql/table/__init__.py +1 -0
  87. ormlambda/{utils → sql/table}/fields.py +6 -5
  88. ormlambda/{utils → sql/table}/table_constructor.py +43 -91
  89. ormlambda/sql/types.py +25 -0
  90. ormlambda/statements/__init__.py +2 -0
  91. ormlambda/statements/base_statement.py +129 -0
  92. ormlambda/statements/interfaces/IStatements.py +309 -0
  93. ormlambda/statements/interfaces/__init__.py +1 -0
  94. ormlambda/statements/types.py +51 -0
  95. ormlambda/utils/__init__.py +1 -3
  96. ormlambda/utils/module_tree/__init__.py +1 -0
  97. ormlambda/utils/module_tree/dynamic_module.py +20 -14
  98. {ormlambda-2.11.1.dist-info → ormlambda-3.7.0.dist-info}/METADATA +132 -68
  99. ormlambda-3.7.0.dist-info/RECORD +117 -0
  100. ormlambda/common/abstract_classes/abstract_model.py +0 -115
  101. ormlambda/common/interfaces/IAggregate.py +0 -10
  102. ormlambda/common/interfaces/IStatements.py +0 -348
  103. ormlambda/components/where/__init__.py +0 -1
  104. ormlambda/components/where/abstract_where.py +0 -15
  105. ormlambda/databases/my_sql/clauses/where_condition.py +0 -222
  106. ormlambda/model_base.py +0 -36
  107. ormlambda/utils/column.py +0 -105
  108. ormlambda/utils/foreign_key.py +0 -81
  109. ormlambda/utils/lambda_disassembler/__init__.py +0 -4
  110. ormlambda/utils/lambda_disassembler/dis_types.py +0 -133
  111. ormlambda/utils/lambda_disassembler/disassembler.py +0 -69
  112. ormlambda/utils/lambda_disassembler/dtypes.py +0 -103
  113. ormlambda/utils/lambda_disassembler/name_of.py +0 -41
  114. ormlambda/utils/lambda_disassembler/nested_element.py +0 -44
  115. ormlambda/utils/lambda_disassembler/tree_instruction.py +0 -145
  116. ormlambda-2.11.1.dist-info/RECORD +0 -81
  117. /ormlambda/{utils → sql}/dtypes.py +0 -0
  118. {ormlambda-2.11.1.dist-info → ormlambda-3.7.0.dist-info}/LICENSE +0 -0
  119. {ormlambda-2.11.1.dist-info → ormlambda-3.7.0.dist-info}/WHEEL +0 -0
ormlambda/utils/column.py DELETED
@@ -1,105 +0,0 @@
1
- from __future__ import annotations
2
- from typing import Type, Optional, Callable, TYPE_CHECKING, Any
3
- import shapely as sph
4
-
5
- if TYPE_CHECKING:
6
- from .table_constructor import Field
7
-
8
-
9
- class Column[T]:
10
- CHAR: str = "%s"
11
-
12
- __slots__ = (
13
- "dtype",
14
- "column_name",
15
- "column_value",
16
- "is_primary_key",
17
- "is_auto_generated",
18
- "is_auto_increment",
19
- "is_unique",
20
- )
21
-
22
- def __init__(
23
- self,
24
- dtype: Type[T] = None,
25
- column_name: str = None,
26
- column_value: T = None,
27
- *,
28
- is_primary_key: bool = False,
29
- is_auto_generated: bool = False,
30
- is_auto_increment: bool = False,
31
- is_unique: bool = False,
32
- ) -> None:
33
- self.dtype = dtype
34
- self.column_name = column_name
35
- self.column_value: T = column_value
36
- self.is_primary_key: bool = is_primary_key
37
- self.is_auto_generated: bool = is_auto_generated
38
- self.is_auto_increment: bool = is_auto_increment
39
- self.is_unique: bool = is_unique
40
-
41
- @property
42
- def column_value_to_query(self) -> T:
43
- """
44
- This property must ensure that any variable requiring casting by different database methods is properly wrapped.
45
- """
46
- if self.dtype is sph.Point:
47
- return sph.to_wkt(self.column_value, -1)
48
- return self.column_value
49
-
50
- @property
51
- def placeholder(self) -> str:
52
- return self.placeholder_resolutor(self.dtype)
53
-
54
- @property
55
- def placeholder_resolutor(self) -> Callable[[Type, T], str]:
56
- return self.__fetch_wrapped_method
57
-
58
- # FIXME [ ]: this method is allocating the Column class with MySQL database
59
- @classmethod
60
- def __fetch_wrapped_method(cls, type_: Type) -> Optional[str]:
61
- """
62
- This method must ensure that any variable requiring casting by different database methods is properly wrapped.
63
- """
64
- caster: dict[Type[Any], Callable[[str], str]] = {
65
- sph.Point: lambda x: f"ST_GeomFromText({x})",
66
- }
67
- return caster.get(type_, lambda x: x)(cls.CHAR)
68
-
69
- def __repr__(self) -> str:
70
- return f"<Column: {self.dtype}>"
71
-
72
- def __to_string__(self, field: Field):
73
- column_class_string: str = f"{Column.__name__}[{field.type_name}]("
74
-
75
- dicc: dict[str, Callable[[Field], str]] = {
76
- "dtype": lambda field: field.type_name,
77
- "column_name": lambda field: f"'{field.name}'",
78
- "column_value": lambda field: field.name, # must be the same variable name as the instance variable name in Table's __init__ class
79
- }
80
- for self_var in self.__init__.__annotations__:
81
- if not hasattr(self, self_var):
82
- continue
83
-
84
- self_value = dicc.get(self_var, lambda field: getattr(self, self_var))(field)
85
- column_class_string += f" {self_var}={self_value}, "
86
-
87
- column_class_string += ")"
88
- return column_class_string
89
-
90
- def __hash__(self) -> int:
91
- return hash(
92
- (
93
- self.column_name,
94
- self.column_value,
95
- self.is_primary_key,
96
- self.is_auto_generated,
97
- self.is_auto_increment,
98
- self.is_unique,
99
- )
100
- )
101
-
102
- def __eq__(self, value: "Column") -> bool:
103
- if isinstance(value, Column):
104
- return self.__hash__() == value.__hash__()
105
- return False
@@ -1,81 +0,0 @@
1
- from __future__ import annotations
2
- from typing import Callable, TYPE_CHECKING, NamedTuple, Type, Optional, overload
3
- from .lambda_disassembler import Disassembler
4
-
5
- if TYPE_CHECKING:
6
- from .table_constructor import Table
7
-
8
-
9
- class ReferencedTable[T1: Type[Table], T2: Type[Table]](NamedTuple):
10
- obj: T2
11
- relationship: Callable[[T1, T2], bool]
12
-
13
-
14
- class TableInfo[T1: Type[Table], T2: Type[Table]]:
15
- @overload
16
- def __init__(self) -> None: ...
17
- @overload
18
- def __init__(self, table_object: T1) -> None: ...
19
-
20
- def __init__(self, table_object: Optional[T1] = None) -> None:
21
- self._table_object: Optional[T1] = table_object
22
- self._referenced_tables: dict[str, ReferencedTable[T1, T2]] = {}
23
-
24
- def __repr__(self) -> str:
25
- return f"<{TableInfo.__name__}> class '{self.table_object}' dependent tables -> [{', '.join(tuple(self.referenced_tables))}]"
26
-
27
- @property
28
- def referenced_tables(self) -> dict[str, ReferencedTable[T1, T2]]:
29
- return self._referenced_tables
30
-
31
- def update_referenced_tables(self, referenced_table: Type[Table], relationship: Callable[[T1, T2], bool]) -> None:
32
- self._referenced_tables.update({referenced_table.__table_name__: ReferencedTable[T1, T2](referenced_table, relationship)})
33
-
34
- @property
35
- def table_object(self) -> Optional[Type[Table]]:
36
- return self._table_object
37
-
38
- @table_object.setter
39
- def table_object(self, value: Type[Table]) -> None:
40
- self._table_object = value
41
-
42
- @property
43
- def has_relationship(self) -> bool:
44
- return len(self._referenced_tables) > 0
45
-
46
-
47
- class ForeignKey[Tbl1: Type[Table], Tbl2: Type[Table]]:
48
- MAPPED: dict[str, TableInfo[Tbl1, Tbl2]] = {}
49
-
50
- def __new__(
51
- cls,
52
- orig_table: str,
53
- referenced_table: Type[Tbl2],
54
- relationship: Callable[[Tbl1, Tbl2], bool],
55
- ) -> Tbl2:
56
- cls.add_foreign_key(orig_table, referenced_table, relationship)
57
-
58
- return referenced_table
59
-
60
- @classmethod
61
- def add_foreign_key(cls, orig_table: str, referenced_table: Table, relationship: Callable[[Tbl1, Tbl2], bool]) -> None:
62
- if orig_table not in cls.MAPPED:
63
- cls.MAPPED[orig_table] = TableInfo()
64
-
65
- # if referenced_table not in cls.MAPPED[orig_table]:
66
- cls.MAPPED[orig_table].update_referenced_tables(referenced_table, relationship)
67
-
68
- return None
69
-
70
- @classmethod
71
- def create_query(cls, orig_table: Table) -> list[str]:
72
- clauses: list[str] = []
73
-
74
- fk: TableInfo[Tbl1, Tbl2] = ForeignKey[Tbl1, Tbl2].MAPPED[orig_table.__table_name__]
75
- for referenced_table_obj in fk.referenced_tables.values():
76
- dissambler: Disassembler = Disassembler(referenced_table_obj.relationship)
77
- orig_col: str = dissambler.cond_1.name
78
- referenced_col: str = dissambler.cond_2.name
79
-
80
- clauses.append(f"FOREIGN KEY ({orig_col}) REFERENCES {referenced_table_obj.obj.__table_name__}({referenced_col})")
81
- return clauses
@@ -1,4 +0,0 @@
1
- from .disassembler import Disassembler # noqa: F401
2
- from .nested_element import NestedElement # noqa: F401
3
- from .tree_instruction import TreeInstruction, TupleInstruction # noqa: F401
4
- from .name_of import nameof # noqa: F401
@@ -1,133 +0,0 @@
1
- from enum import Enum
2
-
3
-
4
- class OpName(Enum):
5
- CACHE = "CACHE"
6
- POP_TOP = "POP_TOP"
7
- PUSH_NULL = "PUSH_NULL"
8
- INTERPRETER_EXIT = "INTERPRETER_EXIT"
9
- END_FOR = "END_FOR"
10
- END_SEND = "END_SEND"
11
- NOP = "NOP"
12
- UNARY_NEGATIVE = "UNARY_NEGATIVE"
13
- UNARY_NOT = "UNARY_NOT"
14
- UNARY_INVERT = "UNARY_INVERT"
15
- RESERVED = "RESERVED"
16
- BINARY_SUBSCR = "BINARY_SUBSCR"
17
- BINARY_SLICE = "BINARY_SLICE"
18
- STORE_SLICE = "STORE_SLICE"
19
- GET_LEN = "GET_LEN"
20
- MATCH_MAPPING = "MATCH_MAPPING"
21
- MATCH_SEQUENCE = "MATCH_SEQUENCE"
22
- MATCH_KEYS = "MATCH_KEYS"
23
- PUSH_EXC_INFO = "PUSH_EXC_INFO"
24
- CHECK_EXC_MATCH = "CHECK_EXC_MATCH"
25
- CHECK_EG_MATCH = "CHECK_EG_MATCH"
26
- WITH_EXCEPT_START = "WITH_EXCEPT_START"
27
- GET_AITER = "GET_AITER"
28
- GET_ANEXT = "GET_ANEXT"
29
- BEFORE_ASYNC_WITH = "BEFORE_ASYNC_WITH"
30
- BEFORE_WITH = "BEFORE_WITH"
31
- END_ASYNC_FOR = "END_ASYNC_FOR"
32
- CLEANUP_THROW = "CLEANUP_THROW"
33
- STORE_SUBSCR = "STORE_SUBSCR"
34
- DELETE_SUBSCR = "DELETE_SUBSCR"
35
- GET_ITER = "GET_ITER"
36
- GET_YIELD_FROM_ITER = "GET_YIELD_FROM_ITER"
37
- LOAD_BUILD_CLASS = "LOAD_BUILD_CLASS"
38
- LOAD_ASSERTION_ERROR = "LOAD_ASSERTION_ERROR"
39
- RETURN_GENERATOR = "RETURN_GENERATOR"
40
- RETURN_VALUE = "RETURN_VALUE"
41
- SETUP_ANNOTATIONS = "SETUP_ANNOTATIONS"
42
- LOAD_LOCALS = "LOAD_LOCALS"
43
- POP_EXCEPT = "POP_EXCEPT"
44
- UNPACK_SEQUENCE = "UNPACK_SEQUENCE"
45
- UNPACK_EX = "UNPACK_EX"
46
- SWAP = "SWAP"
47
- LOAD_CONST = "LOAD_CONST"
48
- BUILD_TUPLE = "BUILD_TUPLE"
49
- BUILD_LIST = "BUILD_LIST"
50
- BUILD_SET = "BUILD_SET"
51
- BUILD_MAP = "BUILD_MAP"
52
- COMPARE_OP = "COMPARE_OP"
53
- IS_OP = "IS_OP"
54
- CONTAINS_OP = "CONTAINS_OP"
55
- RERAISE = "RERAISE"
56
- COPY = "COPY"
57
- RETURN_CONST = "RETURN_CONST"
58
- BINARY_OP = "BINARY_OP"
59
- LOAD_FAST = "LOAD_FAST"
60
- STORE_FAST = "STORE_FAST"
61
- DELETE_FAST = "DELETE_FAST"
62
- LOAD_FAST_CHECK = "LOAD_FAST_CHECK"
63
- RAISE_VARARGS = "RAISE_VARARGS"
64
- GET_AWAITABLE = "GET_AWAITABLE"
65
- MAKE_FUNCTION = "MAKE_FUNCTION"
66
- BUILD_SLICE = "BUILD_SLICE"
67
- MAKE_CELL = "MAKE_CELL"
68
- LOAD_CLOSURE = "LOAD_CLOSURE"
69
- LOAD_DEREF = "LOAD_DEREF"
70
- STORE_DEREF = "STORE_DEREF"
71
- DELETE_DEREF = "DELETE_DEREF"
72
- CALL_FUNCTION_EX = "CALL_FUNCTION_EX"
73
- LOAD_FAST_AND_CLEAR = "LOAD_FAST_AND_CLEAR"
74
- EXTENDED_ARG = "EXTENDED_ARG"
75
- LIST_APPEND = "LIST_APPEND"
76
- SET_ADD = "SET_ADD"
77
- MAP_ADD = "MAP_ADD"
78
- COPY_FREE_VARS = "COPY_FREE_VARS"
79
- YIELD_VALUE = "YIELD_VALUE"
80
- RESUME = "RESUME"
81
- MATCH_CLASS = "MATCH_CLASS"
82
- FORMAT_VALUE = "FORMAT_VALUE"
83
- BUILD_CONST_KEY_MAP = "BUILD_CONST_KEY_MAP"
84
- BUILD_STRING = "BUILD_STRING"
85
- LIST_EXTEND = "LIST_EXTEND"
86
- SET_UPDATE = "SET_UPDATE"
87
- DICT_MERGE = "DICT_MERGE"
88
- DICT_UPDATE = "DICT_UPDATE"
89
- CALL = "CALL"
90
- KW_NAMES = "KW_NAMES"
91
- CALL_INTRINSIC_1 = "CALL_INTRINSIC_1"
92
- CALL_INTRINSIC_2 = "CALL_INTRINSIC_2"
93
- LOAD_FROM_DICT_OR_DEREF = "LOAD_FROM_DICT_OR_DEREF"
94
- INSTRUMENTED_LOAD_SUPER_ATTR = "INSTRUMENTED_LOAD_SUPER_ATTR"
95
- INSTRUMENTED_POP_JUMP_IF_NONE = "INSTRUMENTED_POP_JUMP_IF_NONE"
96
- INSTRUMENTED_POP_JUMP_IF_NOT_NONE = "INSTRUMENTED_POP_JUMP_IF_NOT_NONE"
97
- INSTRUMENTED_RESUME = "INSTRUMENTED_RESUME"
98
- INSTRUMENTED_CALL = "INSTRUMENTED_CALL"
99
- INSTRUMENTED_RETURN_VALUE = "INSTRUMENTED_RETURN_VALUE"
100
- INSTRUMENTED_YIELD_VALUE = "INSTRUMENTED_YIELD_VALUE"
101
- INSTRUMENTED_CALL_FUNCTION_EX = "INSTRUMENTED_CALL_FUNCTION_EX"
102
- INSTRUMENTED_JUMP_FORWARD = "INSTRUMENTED_JUMP_FORWARD"
103
- INSTRUMENTED_JUMP_BACKWARD = "INSTRUMENTED_JUMP_BACKWARD"
104
- INSTRUMENTED_RETURN_CONST = "INSTRUMENTED_RETURN_CONST"
105
- INSTRUMENTED_FOR_ITER = "INSTRUMENTED_FOR_ITER"
106
- INSTRUMENTED_POP_JUMP_IF_FALSE = "INSTRUMENTED_POP_JUMP_IF_FALSE"
107
- INSTRUMENTED_POP_JUMP_IF_TRUE = "INSTRUMENTED_POP_JUMP_IF_TRUE"
108
- INSTRUMENTED_END_FOR = "INSTRUMENTED_END_FOR"
109
- INSTRUMENTED_END_SEND = "INSTRUMENTED_END_SEND"
110
- INSTRUMENTED_INSTRUCTION = "INSTRUMENTED_INSTRUCTION"
111
- INSTRUMENTED_LINE = "INSTRUMENTED_LINE"
112
- FOR_ITER = "FOR_ITER"
113
- JUMP_FORWARD = "JUMP_FORWARD"
114
- POP_JUMP_IF_FALSE = "POP_JUMP_IF_FALSE"
115
- POP_JUMP_IF_TRUE = "POP_JUMP_IF_TRUE"
116
- SEND = "SEND"
117
- POP_JUMP_IF_NOT_NONE = "POP_JUMP_IF_NOT_NONE"
118
- POP_JUMP_IF_NONE = "POP_JUMP_IF_NONE"
119
- JUMP_BACKWARD_NO_INTERRUPT = "JUMP_BACKWARD_NO_INTERRUPT"
120
- JUMP_BACKWARD = "JUMP_BACKWARD"
121
- STORE_NAME = "STORE_NAME"
122
- DELETE_NAME = "DELETE_NAME"
123
- STORE_ATTR = "STORE_ATTR"
124
- DELETE_ATTR = "DELETE_ATTR"
125
- STORE_GLOBAL = "STORE_GLOBAL"
126
- DELETE_GLOBAL = "DELETE_GLOBAL"
127
- LOAD_NAME = "LOAD_NAME"
128
- LOAD_ATTR = "LOAD_ATTR"
129
- IMPORT_NAME = "IMPORT_NAME"
130
- IMPORT_FROM = "IMPORT_FROM"
131
- LOAD_GLOBAL = "LOAD_GLOBAL"
132
- LOAD_SUPER_ATTR = "LOAD_SUPER_ATTR"
133
- LOAD_FROM_DICT_OR_GLOBALS = "LOAD_FROM_DICT_OR_GLOBALS"
@@ -1,69 +0,0 @@
1
- import dis
2
- from typing import Any, Callable, overload
3
-
4
- from .nested_element import NestedElement
5
- from .tree_instruction import TreeInstruction
6
-
7
-
8
- class Disassembler[TProp1, TProp2: Any]:
9
- """
10
- class to dissambler lambda function to detach information from left to right of compare symbol.
11
-
12
- >>> dis = Disassembler[DtoC, None](lambda d: d.c.b.b_data == "asdf")
13
-
14
- >>> dis.cond_1.name # b_data
15
- >>> dis.cond_1.parent.parent.parent.name # d
16
- >>> dis.cond_1.parent.parent.name # c
17
-
18
- >>> dis.cond_2.name, "asdf"
19
-
20
- >>> dis.compare_op, "="
21
-
22
- """
23
-
24
- __slots__ = (
25
- "_function",
26
- "_bytecode_function",
27
- "_cond_1",
28
- "_cond_2",
29
- "_compare_op",
30
- )
31
-
32
- @overload
33
- def __init__(self, function: Callable[[], bool]) -> None: ...
34
-
35
- @overload
36
- def __init__(self, function: Callable[[TProp1], bool]) -> None: ...
37
-
38
- @overload
39
- def __init__(self, function: Callable[[TProp1, TProp2], bool]) -> None: ...
40
-
41
- def __init__(self, function: Callable[[], bool] | Callable[[TProp1], bool] | Callable[[TProp1, TProp2], bool]) -> None:
42
- self._function: Callable[[], bool] | Callable[[TProp1], bool] | Callable[[TProp1, TProp2], bool] = function
43
- self._bytecode_function: dis.Bytecode = dis.Bytecode(function)
44
- self.__init_custom__()
45
-
46
- def __repr__(self) -> str:
47
- return f"<{self.__class__.__name__}>: {self._cond_1.name} {self._cond_2.name} {self._compare_op}"
48
-
49
- def __init_custom__(self):
50
- tree = TreeInstruction(self._function)
51
- dicc = tree.to_list()
52
- self._compare_op: str = tree.compare_op[0]
53
-
54
- self._cond_1: NestedElement[TProp1] = dicc[0].nested_element
55
- self._cond_2: NestedElement[TProp2] = dicc[1].nested_element
56
-
57
- return None
58
-
59
- @property
60
- def cond_1(self) -> NestedElement[str]:
61
- return self._cond_1
62
-
63
- @property
64
- def cond_2(self) -> NestedElement[str]:
65
- return self._cond_2
66
-
67
- @property
68
- def compare_op(self) -> str:
69
- return self._compare_op
@@ -1,103 +0,0 @@
1
- """
2
- String Data Types
3
- Data type Description
4
- CHAR(size) A FIXED length string (can contain letters, numbers, and special characters). The size parameter specifies the column length in characters - can be from 0 to 255. Default is 1
5
- VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special characters). The size parameter specifies the maximum column length in characters - can be from 0 to 65535
6
- BINARY(size) Equal to CHAR(), but stores binary byte strings. The size parameter specifies the column length in bytes. Default is 1
7
- VARBINARY(size) Equal to VARCHAR(), but stores binary byte strings. The size parameter specifies the maximum column length in bytes.
8
- TINYBLOB For BLOBs (Binary Large OBjects). Max length: 255 bytes
9
- TINYTEXT Holds a string with a maximum length of 255 characters
10
- TEXT(size) Holds a string with a maximum length of 65,535 bytes
11
- BLOB(size) For BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data
12
- MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters
13
- MEDIUMBLOB For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes of data
14
- LONGTEXT Holds a string with a maximum length of 4,294,967,295 characters
15
- LONGBLOB For BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data
16
- ENUM(val1, val2, val3, ...) A string object that can have only one value, chosen from a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted. The values are sorted in the order you enter them
17
- SET(val1, val2, val3, ...) A string object that can have 0 or more values, chosen from a list of possible values. You can list up to 64 values in a SET list
18
- Numeric Data Types
19
- Data type Description
20
- BIT(size) A bit-value type. The number of bits per value is specified in size. The size parameter can hold a value from 1 to 64. The default value for size is 1.
21
- TINYINT(size) A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255. The size parameter specifies the maximum display width (which is 255)
22
- BOOL Zero is considered as false, nonzero values are considered as true.
23
- BOOLEAN Equal to BOOL
24
- SMALLINT(size) A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to 65535. The size parameter specifies the maximum display width (which is 255)
25
- MEDIUMINT(size) A medium integer. Signed range is from -8388608 to 8388607. Unsigned range is from 0 to 16777215. The size parameter specifies the maximum display width (which is 255)
26
- INT(size) A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range is from 0 to 4294967295. The size parameter specifies the maximum display width (which is 255)
27
- INTEGER(size) Equal to INT(size)
28
- BIGINT(size) A large integer. Signed range is from -9223372036854775808 to 9223372036854775807. Unsigned range is from 0 to 18446744073709551615. The size parameter specifies the maximum display width (which is 255)
29
- FLOAT(size, d) A floating point number. The total number of digits is specified in size. The number of digits after the decimal point is specified in the d parameter. This syntax is deprecated in MySQL 8.0.17, and it will be removed in future MySQL versions
30
- FLOAT(p) A floating point number. MySQL uses the p value to determine whether to use FLOAT or DOUBLE for the resulting data type. If p is from 0 to 24, the data type becomes FLOAT(). If p is from 25 to 53, the data type becomes DOUBLE()
31
- DOUBLE(size, d) A normal-size floating point number. The total number of digits is specified in size. The number of digits after the decimal point is specified in the d parameter
32
- DOUBLE PRECISION(size, d)
33
- DECIMAL(size, d) An exact fixed-point number. The total number of digits is specified in size. The number of digits after the decimal point is specified in the d parameter. The maximum number for size is 65. The maximum number for d is 30. The default value for size is 10. The default value for d is 0.
34
- DEC(size, d) Equal to DECIMAL(size,d)
35
- Note: All the numeric data types may have an extra option: UNSIGNED or ZEROFILL. If you add the UNSIGNED option, MySQL disallows negative values for the column. If you add the ZEROFILL option, MySQL automatically also adds the UNSIGNED attribute to the column.
36
-
37
- Date and Time Data Types
38
- Data type Description
39
- DATE A date. Format: YYYY-MM-DD. The supported range is from '1000-01-01' to '9999-12-31'
40
- DATETIME(fsp) A date and time combination. Format: YYYY-MM-DD hh:mm:ss. The supported range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. Adding DEFAULT and ON UPDATE in the column definition to get automatic initialization and updating to the current date and time
41
- TIMESTAMP(fsp) A timestamp. TIMESTAMP values are stored as the number of seconds since the Unix epoch ('1970-01-01 00:00:00' UTC). Format: YYYY-MM-DD hh:mm:ss. The supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC. Automatic initialization and updating to the current date and time can be specified using DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP in the column definition
42
- TIME(fsp) A time. Format: hh:mm:ss. The supported range is from '-838:59:59' to '838:59:59'
43
- YEAR A year in four-digit format. Values allowed in four-digit format: 1901 to 2155, and 0000.
44
- MySQL 8.0 does not support year in two-digit format.
45
- """
46
-
47
- from typing import Literal
48
-
49
-
50
- STRING = Literal[
51
- "CHAR(size)",
52
- "VARCHAR(size)",
53
- "BINARY(size)",
54
- "VARBINARY(size)",
55
- "TINYBLOB",
56
- "TINYTEXT",
57
- "TEXT(size)",
58
- "BLOB(size)",
59
- "MEDIUMTEXT",
60
- "MEDIUMBLOB",
61
- "LONGTEXT",
62
- "LONGBLOB",
63
- "ENUM(val1, val2, val3, ...)",
64
- "SET(val1, val2, val3, ...)",
65
- ]
66
-
67
- NUMERIC_SIGNED = Literal[
68
- "BIT(size)",
69
- "TINYINT(size)",
70
- "BOOL",
71
- "BOOLEAN",
72
- "SMALLINT(size)",
73
- "MEDIUMINT(size)",
74
- "INT(size)",
75
- "INTEGER(size)",
76
- "BIGINT(size)",
77
- "FLOAT(size, d)",
78
- "FLOAT(p)",
79
- "DOUBLE(size, d)",
80
- "DOUBLE PRECISION(size, d)",
81
- "DECIMAL(size, d)",
82
- "DEC(size, d)",
83
- ]
84
-
85
- NUMERIC_UNSIGNED = Literal[
86
- "BIT(size)",
87
- "TINYINT(size)",
88
- "BOOL",
89
- "BOOLEAN",
90
- "SMALLINT(size)",
91
- "MEDIUMINT(size)",
92
- "INT(size)",
93
- "INTEGER(size)",
94
- "BIGINT(size)",
95
- "FLOAT(size, d)",
96
- "FLOAT(p)",
97
- "DOUBLE(size, d)",
98
- "DOUBLE PRECISION(size, d)",
99
- "DECIMAL(size, d)",
100
- "DEC(size, d)",
101
- ]
102
-
103
- DATE = Literal["DATE", "DATETIME(fsp)", "TIMESTAMP(fsp)", "TIME(fsp)", "YEAR"]
@@ -1,41 +0,0 @@
1
- import inspect
2
- import re
3
-
4
-
5
- def nameof(_, full_name=False) -> str:
6
- """
7
- Return the name of the variable passed as argument
8
-
9
- >>> class C:
10
- ... member = 5
11
- >>> my_var = C()
12
- >>> nameof(my_var)
13
- 'my_var'
14
- >>> nameof(my_var.member)
15
- 'member'
16
- >>> nameof(my_var.member, full_name=True)
17
- 'my_var.member'
18
-
19
- >>> nameof(4 + (my_var.member) + 11)
20
- Traceback (most recent call last):
21
- ...
22
- RuntimeError: Invalid nameof invocation: nameof(4 + (my_var.member) + 11)
23
- >>> nameof(4)
24
- Traceback (most recent call last):
25
- ...
26
- RuntimeError: Invalid nameof invocation: nameof(4)
27
- """
28
- s = inspect.stack()
29
- func_name = s[0].frame.f_code.co_name
30
- call = s[1].code_context[0].strip()
31
- # Simple search for first closing bracket or comma
32
- arg = re.search(rf"{func_name}\(([^,)]+)[,)]", call)
33
- if arg is not None:
34
- var_parts = arg.group(1).split(".")
35
- if arg is None or not all(map(str.isidentifier, var_parts)):
36
- raise RuntimeError(f"Invalid {func_name} invocation: {call}")
37
-
38
- if full_name:
39
- return arg.group(1)
40
- else:
41
- return var_parts[-1]
@@ -1,44 +0,0 @@
1
- from typing import Iterable
2
-
3
-
4
- class NestedElement[T]:
5
- def __init__(self, cond: T):
6
- self._cond: T = cond
7
- self._parent_list: list[str] = self._create_parent_list(cond)
8
-
9
- def __repr__(self) -> str:
10
- return f"{NestedElement.__name__}: {'.'.join(self._parent_list)}"
11
-
12
- @property
13
- def name(self) -> T:
14
- if self._parent_list:
15
- return self._parent_list[-1]
16
- else:
17
- return self._cond
18
-
19
- @property
20
- def parent(self) -> "NestedElement":
21
- if not self._parent_list:
22
- raise ValueError(f"Attribute '{self._cond}' has not parent values")
23
- new_cond = self._parent_list[:-1]
24
- return self.__get_parent(new_cond)
25
-
26
- @property
27
- def parents(self) -> list[T]:
28
- return self._parent_list
29
-
30
- def _create_parent_list(self, condition: T) -> Iterable[str]:
31
- if isinstance(condition, Iterable) and not isinstance(condition, str):
32
- return condition
33
-
34
- try:
35
- _list: list[str] = condition.split(".")
36
-
37
- except Exception:
38
- return []
39
- else:
40
- return _list
41
-
42
- @staticmethod
43
- def __get_parent(constructor: T) -> "NestedElement":
44
- return NestedElement[T](constructor)