ormlambda 3.12.2__py3-none-any.whl → 3.34.1__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 (145) hide show
  1. ormlambda/__init__.py +2 -0
  2. ormlambda/caster/__init__.py +1 -1
  3. ormlambda/caster/caster.py +29 -12
  4. ormlambda/common/abstract_classes/clause_info_converter.py +4 -12
  5. ormlambda/common/abstract_classes/decomposition_query.py +17 -2
  6. ormlambda/common/abstract_classes/non_query_base.py +9 -7
  7. ormlambda/common/abstract_classes/query_base.py +3 -1
  8. ormlambda/common/errors/__init__.py +29 -0
  9. ormlambda/common/interfaces/IQueryCommand.py +6 -2
  10. ormlambda/databases/__init__.py +0 -1
  11. ormlambda/databases/my_sql/__init__.py +0 -1
  12. ormlambda/databases/my_sql/caster/caster.py +23 -19
  13. ormlambda/databases/my_sql/caster/types/__init__.py +3 -0
  14. ormlambda/databases/my_sql/caster/types/boolean.py +35 -0
  15. ormlambda/databases/my_sql/caster/types/bytes.py +7 -7
  16. ormlambda/databases/my_sql/caster/types/date.py +34 -0
  17. ormlambda/databases/my_sql/caster/types/datetime.py +7 -7
  18. ormlambda/databases/my_sql/caster/types/decimal.py +32 -0
  19. ormlambda/databases/my_sql/caster/types/float.py +7 -7
  20. ormlambda/databases/my_sql/caster/types/int.py +7 -7
  21. ormlambda/databases/my_sql/caster/types/iterable.py +7 -7
  22. ormlambda/databases/my_sql/caster/types/none.py +8 -7
  23. ormlambda/databases/my_sql/caster/types/point.py +4 -4
  24. ormlambda/databases/my_sql/caster/types/string.py +7 -7
  25. ormlambda/databases/my_sql/clauses/ST_AsText.py +8 -7
  26. ormlambda/databases/my_sql/clauses/ST_Contains.py +10 -5
  27. ormlambda/databases/my_sql/clauses/__init__.py +4 -10
  28. ormlambda/databases/my_sql/clauses/count.py +5 -15
  29. ormlambda/databases/my_sql/clauses/delete.py +3 -50
  30. ormlambda/databases/my_sql/clauses/group_by.py +3 -16
  31. ormlambda/databases/my_sql/clauses/having.py +2 -6
  32. ormlambda/databases/my_sql/clauses/insert.py +4 -92
  33. ormlambda/databases/my_sql/clauses/joins.py +5 -140
  34. ormlambda/databases/my_sql/clauses/limit.py +4 -15
  35. ormlambda/databases/my_sql/clauses/offset.py +4 -15
  36. ormlambda/databases/my_sql/clauses/order.py +4 -61
  37. ormlambda/databases/my_sql/clauses/update.py +4 -67
  38. ormlambda/databases/my_sql/clauses/upsert.py +3 -66
  39. ormlambda/databases/my_sql/clauses/where.py +4 -42
  40. ormlambda/databases/my_sql/repository.py +217 -0
  41. ormlambda/dialects/__init__.py +39 -0
  42. ormlambda/dialects/default/__init__.py +1 -0
  43. ormlambda/dialects/default/base.py +39 -0
  44. ormlambda/dialects/interface/__init__.py +1 -0
  45. ormlambda/dialects/interface/dialect.py +78 -0
  46. ormlambda/dialects/mysql/__init__.py +8 -0
  47. ormlambda/dialects/mysql/base.py +387 -0
  48. ormlambda/dialects/mysql/mysqlconnector.py +46 -0
  49. ormlambda/dialects/mysql/types.py +732 -0
  50. ormlambda/dialects/sqlite/__init__.py +5 -0
  51. ormlambda/dialects/sqlite/base.py +47 -0
  52. ormlambda/dialects/sqlite/pysqlite.py +32 -0
  53. ormlambda/engine/__init__.py +1 -0
  54. ormlambda/engine/base.py +58 -0
  55. ormlambda/engine/create.py +9 -23
  56. ormlambda/engine/url.py +31 -19
  57. ormlambda/env.py +30 -0
  58. ormlambda/errors.py +17 -0
  59. ormlambda/model/base_model.py +7 -9
  60. ormlambda/repository/base_repository.py +36 -5
  61. ormlambda/repository/interfaces/IRepositoryBase.py +121 -7
  62. ormlambda/repository/response.py +134 -0
  63. ormlambda/sql/clause_info/aggregate_function_base.py +19 -9
  64. ormlambda/sql/clause_info/clause_info.py +34 -17
  65. ormlambda/sql/clauses/__init__.py +14 -0
  66. ormlambda/{databases/my_sql → sql}/clauses/alias.py +23 -6
  67. ormlambda/sql/clauses/count.py +57 -0
  68. ormlambda/sql/clauses/delete.py +71 -0
  69. ormlambda/sql/clauses/group_by.py +30 -0
  70. ormlambda/sql/clauses/having.py +21 -0
  71. ormlambda/sql/clauses/insert.py +104 -0
  72. ormlambda/sql/clauses/interfaces/__init__.py +5 -0
  73. ormlambda/{components → sql/clauses}/join/join_context.py +15 -7
  74. ormlambda/sql/clauses/joins.py +159 -0
  75. ormlambda/sql/clauses/limit.py +15 -0
  76. ormlambda/sql/clauses/offset.py +15 -0
  77. ormlambda/sql/clauses/order.py +55 -0
  78. ormlambda/{databases/my_sql → sql}/clauses/select.py +12 -13
  79. ormlambda/sql/clauses/update.py +84 -0
  80. ormlambda/sql/clauses/upsert.py +77 -0
  81. ormlambda/sql/clauses/where.py +65 -0
  82. ormlambda/sql/column/__init__.py +1 -0
  83. ormlambda/sql/{column.py → column/column.py} +82 -22
  84. ormlambda/sql/comparer.py +51 -37
  85. ormlambda/sql/compiler.py +427 -0
  86. ormlambda/sql/ddl.py +68 -0
  87. ormlambda/sql/elements.py +36 -0
  88. ormlambda/sql/foreign_key.py +43 -39
  89. ormlambda/{databases/my_sql → sql}/functions/concat.py +13 -5
  90. ormlambda/{databases/my_sql → sql}/functions/max.py +9 -4
  91. ormlambda/{databases/my_sql → sql}/functions/min.py +9 -13
  92. ormlambda/{databases/my_sql → sql}/functions/sum.py +8 -10
  93. ormlambda/sql/sqltypes.py +647 -0
  94. ormlambda/sql/table/__init__.py +1 -1
  95. ormlambda/sql/table/table.py +179 -0
  96. ormlambda/sql/table/table_constructor.py +1 -208
  97. ormlambda/sql/type_api.py +35 -0
  98. ormlambda/sql/types.py +3 -1
  99. ormlambda/sql/visitors.py +74 -0
  100. ormlambda/statements/__init__.py +1 -0
  101. ormlambda/statements/base_statement.py +28 -38
  102. ormlambda/statements/interfaces/IStatements.py +5 -4
  103. ormlambda/{databases/my_sql → statements}/query_builder.py +35 -30
  104. ormlambda/{databases/my_sql → statements}/statements.py +50 -60
  105. ormlambda/statements/types.py +2 -2
  106. ormlambda/types/__init__.py +24 -0
  107. ormlambda/types/metadata.py +42 -0
  108. ormlambda/util/__init__.py +88 -0
  109. ormlambda/util/load_module.py +21 -0
  110. ormlambda/util/plugin_loader.py +32 -0
  111. ormlambda/util/typing.py +6 -0
  112. ormlambda-3.34.1.dist-info/AUTHORS +32 -0
  113. {ormlambda-3.12.2.dist-info → ormlambda-3.34.1.dist-info}/METADATA +2 -3
  114. ormlambda-3.34.1.dist-info/RECORD +157 -0
  115. {ormlambda-3.12.2.dist-info → ormlambda-3.34.1.dist-info}/WHEEL +1 -1
  116. ormlambda/components/__init__.py +0 -4
  117. ormlambda/components/delete/__init__.py +0 -2
  118. ormlambda/components/delete/abstract_delete.py +0 -17
  119. ormlambda/components/insert/__init__.py +0 -2
  120. ormlambda/components/insert/abstract_insert.py +0 -25
  121. ormlambda/components/select/__init__.py +0 -1
  122. ormlambda/components/update/__init__.py +0 -2
  123. ormlambda/components/update/abstract_update.py +0 -29
  124. ormlambda/components/upsert/__init__.py +0 -2
  125. ormlambda/components/upsert/abstract_upsert.py +0 -25
  126. ormlambda/databases/my_sql/clauses/create_database.py +0 -35
  127. ormlambda/databases/my_sql/clauses/drop_database.py +0 -17
  128. ormlambda/databases/my_sql/repository/__init__.py +0 -1
  129. ormlambda/databases/my_sql/repository/repository.py +0 -351
  130. ormlambda/engine/template.py +0 -47
  131. ormlambda/sql/dtypes.py +0 -94
  132. ormlambda/utils/__init__.py +0 -1
  133. ormlambda-3.12.2.dist-info/RECORD +0 -125
  134. /ormlambda/databases/my_sql/{types.py → pool_types.py} +0 -0
  135. /ormlambda/{components/delete → sql/clauses/interfaces}/IDelete.py +0 -0
  136. /ormlambda/{components/insert → sql/clauses/interfaces}/IInsert.py +0 -0
  137. /ormlambda/{components/select → sql/clauses/interfaces}/ISelect.py +0 -0
  138. /ormlambda/{components/update → sql/clauses/interfaces}/IUpdate.py +0 -0
  139. /ormlambda/{components/upsert → sql/clauses/interfaces}/IUpsert.py +0 -0
  140. /ormlambda/{components → sql/clauses}/join/__init__.py +0 -0
  141. /ormlambda/{databases/my_sql → sql}/functions/__init__.py +0 -0
  142. /ormlambda/{utils → util}/module_tree/__init__.py +0 -0
  143. /ormlambda/{utils → util}/module_tree/dfs_traversal.py +0 -0
  144. /ormlambda/{utils → util}/module_tree/dynamic_module.py +0 -0
  145. {ormlambda-3.12.2.dist-info → ormlambda-3.34.1.dist-info}/LICENSE +0 -0
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
- from typing import Iterable, Type, Optional, TYPE_CHECKING, overload
3
2
  import abc
3
+ from typing import Annotated, Any, Iterable, Type, Optional, TYPE_CHECKING, get_type_hints, overload, get_origin, get_args
4
4
  from ormlambda.sql.types import TableType, ComparerType, ColumnType
5
5
  from ormlambda import ConditionType
6
6
 
@@ -8,6 +8,19 @@ if TYPE_CHECKING:
8
8
  import re
9
9
  from ormlambda import Table
10
10
  from ormlambda.sql.comparer import Comparer, Regex, Like
11
+ from ormlambda.sql.type_api import TypeEngine
12
+
13
+
14
+ from ormlambda.types import (
15
+ # metadata
16
+ PrimaryKey,
17
+ AutoGenerated,
18
+ AutoIncrement,
19
+ Unique,
20
+ CheckTypes,
21
+ Default,
22
+ NotNull,
23
+ )
11
24
 
12
25
 
13
26
  class Column[TProp]:
@@ -21,6 +34,9 @@ class Column[TProp]:
21
34
  "is_auto_generated",
22
35
  "is_auto_increment",
23
36
  "is_unique",
37
+ "is_not_null",
38
+ "default_value",
39
+ "sql_type",
24
40
  "__private_name",
25
41
  "_check",
26
42
  )
@@ -37,7 +53,9 @@ class Column[TProp]:
37
53
  is_auto_generated: bool = False,
38
54
  is_auto_increment: bool = False,
39
55
  is_unique: bool = False,
56
+ is_not_null: bool = False,
40
57
  check_types: bool = True,
58
+ default: Optional[Any] = None,
41
59
  ) -> None: ...
42
60
 
43
61
  def __init__[T: Table](
@@ -48,8 +66,10 @@ class Column[TProp]:
48
66
  is_auto_generated: bool = False,
49
67
  is_auto_increment: bool = False,
50
68
  is_unique: bool = False,
69
+ is_not_null: bool = False,
51
70
  check_types: bool = True,
52
71
  column_name: Optional[str] = None,
72
+ default: Optional[Any] = None,
53
73
  ) -> None:
54
74
  if dtype is None and column_name is None:
55
75
  raise AttributeError("You must specify either the 'dtype' or 'column_name' attribute.")
@@ -62,14 +82,17 @@ class Column[TProp]:
62
82
  self.column_name: Optional[str] = column_name
63
83
  self.__private_name: Optional[str] = None
64
84
  self._check = check_types
85
+ self.default_value: TProp = default
86
+ self.sql_type: TypeEngine[TProp] = None
65
87
 
66
88
  self.is_primary_key: bool = is_primary_key
67
89
  self.is_auto_generated: bool = is_auto_generated
68
90
  self.is_auto_increment: bool = is_auto_increment
69
91
  self.is_unique: bool = is_unique
92
+ self.is_not_null: bool = is_not_null
70
93
 
71
94
  def __repr__(self) -> str:
72
- return f"{type(self).__name__}[{self.dtype.__name__}] => {self.column_name}"
95
+ return f"{type(self).__name__}[{self.dtype.__class__.__name__}] => {self.column_name}"
73
96
 
74
97
  def __str__(self) -> str:
75
98
  return self.table.__table_name__ + "." + self.column_name
@@ -79,6 +102,8 @@ class Column[TProp]:
79
102
  self.column_name = name
80
103
  self.__private_name = self.PRIVATE_CHAR + name
81
104
 
105
+ self._fill_from_annotations(owner, name)
106
+
82
107
  def __get__(self, obj, objtype=None) -> ColumnType[TProp]:
83
108
  if not obj:
84
109
  return self
@@ -100,43 +125,78 @@ class Column[TProp]:
100
125
  self.is_auto_generated,
101
126
  self.is_auto_increment,
102
127
  self.is_unique,
128
+ self.is_not_null,
103
129
  )
104
130
  )
105
131
 
132
+ def _fill_from_annotations[T: Table](self, obj: Type[T], name: str) -> None:
133
+ """Read the metada when using Annotated typing class, and set the attributes accordingly"""
134
+
135
+ from ormlambda.sql.type_api import TypeEngine
136
+
137
+ annotations = get_type_hints(obj, include_extras=True)
138
+ if name in annotations:
139
+ annotation = annotations[name]
140
+ if get_origin(annotation) is Annotated:
141
+ dtype, *metadata = get_args(annotation)
142
+
143
+ if not self.dtype:
144
+ self.dtype = dtype
145
+
146
+ for meta in metadata:
147
+ if isinstance(meta, TypeEngine):
148
+ self.sql_type = meta
149
+ elif isinstance(meta, PrimaryKey):
150
+ self.is_primary_key = True
151
+ elif isinstance(meta, AutoGenerated):
152
+ self.is_auto_generated = True
153
+ elif isinstance(meta, AutoIncrement):
154
+ self.is_auto_increment = True
155
+ elif isinstance(meta, Unique):
156
+ self.is_unique = True
157
+ elif isinstance(meta, CheckTypes):
158
+ self._check = True
159
+ elif isinstance(meta, Default):
160
+ self.default_value = meta.value
161
+ self.is_auto_generated = True
162
+ elif isinstance(meta, NotNull):
163
+ self.is_not_null = True
164
+ return None
165
+
106
166
  @abc.abstractmethod
107
- def __comparer_creator[LTable: Table, OTherTable: Table, OTherType](self, other: ColumnType[OTherType], compare: ComparerType, *args) -> Comparer:
167
+ def __comparer_creator(self, other: ColumnType, compare: ComparerType) -> Comparer:
108
168
  from ormlambda.sql.comparer import Comparer
109
169
 
110
- return Comparer[LTable, TProp, OTherTable, OTherType](self, other, compare, *args)
170
+ return Comparer(self, other, compare)
111
171
 
112
- def __eq__[LTable, OTherTable, OTherProp](self, other: ColumnType[OTherProp], *args) -> Comparer[LTable, TProp, OTherTable, OTherProp]:
113
- return self.__comparer_creator(other, ConditionType.EQUAL.value, *args)
172
+ def __eq__(self, other: ColumnType) -> Comparer:
173
+ return self.__comparer_creator(other, ConditionType.EQUAL.value)
114
174
 
115
- def __ne__[LTable, OTherTable, OtherProp](self, other: ColumnType[OtherProp], *args) -> Comparer[LTable, TProp, OTherTable, OtherProp]:
116
- return self.__comparer_creator(other, ConditionType.NOT_EQUAL.value, *args)
175
+ def __ne__(self, other: ColumnType) -> Comparer:
176
+ return self.__comparer_creator(other, ConditionType.NOT_EQUAL.value)
117
177
 
118
- def __lt__[LTable, OTherTable, OtherProp](self, other: ColumnType[OtherProp], *args) -> Comparer[LTable, TProp, OTherTable, OtherProp]:
119
- return self.__comparer_creator(other, ConditionType.LESS_THAN.value, *args)
178
+ def __lt__(self, other: ColumnType) -> Comparer:
179
+ return self.__comparer_creator(other, ConditionType.LESS_THAN.value)
120
180
 
121
- def __le__[LTable, OTherTable, OtherProp](self, other: ColumnType[OtherProp], *args) -> Comparer[LTable, TProp, OTherTable, OtherProp]:
122
- return self.__comparer_creator(other, ConditionType.LESS_THAN_OR_EQUAL.value, *args)
181
+ def __le__(self, other: ColumnType) -> Comparer:
182
+ return self.__comparer_creator(other, ConditionType.LESS_THAN_OR_EQUAL.value)
123
183
 
124
- def __gt__[LTable, OTherTable, OtherProp](self, other: ColumnType[OtherProp], *args) -> Comparer[LTable, TProp, OTherTable, OtherProp]:
125
- return self.__comparer_creator(other, ConditionType.GREATER_THAN.value, *args)
184
+ def __gt__(self, other: ColumnType) -> Comparer:
185
+ return self.__comparer_creator(other, ConditionType.GREATER_THAN.value)
126
186
 
127
- def __ge__[LTable, OTherTable, OtherProp](self, other: ColumnType[OtherProp], *args) -> Comparer[LTable, TProp, OTherTable, OtherProp]:
128
- return self.__comparer_creator(other, ConditionType.GREATER_THAN_OR_EQUAL.value, *args)
187
+ def __ge__(self, other: ColumnType) -> Comparer:
188
+ return self.__comparer_creator(other, ConditionType.GREATER_THAN_OR_EQUAL.value)
129
189
 
130
- def contains[LTable, OTherTable, OtherProp](self, other: ColumnType[OtherProp], *args) -> Comparer[LTable, TProp, OTherTable, OtherProp]:
190
+ def contains(self, other: ColumnType) -> Comparer:
131
191
  if not isinstance(other, tuple) and isinstance(other, Iterable):
132
192
  other = tuple(other)
133
193
 
134
- return self.__comparer_creator(other, ConditionType.IN.value, *args)
194
+ return self.__comparer_creator(other, ConditionType.IN.value)
135
195
 
136
- def not_contains[LTable, OTherTable, OtherProp](self, other: ColumnType[OtherProp], *args) -> Comparer[LTable, TProp, OTherTable, OtherProp]:
137
- return self.__comparer_creator(other, ConditionType.NOT_IN.value, *args)
196
+ def not_contains(self, other: ColumnType) -> Comparer:
197
+ return self.__comparer_creator(other, ConditionType.NOT_IN.value)
138
198
 
139
- def regex[LProp, RProp](self, pattern: str, flags: Optional[re.RegexFlag | Iterable[re.RegexFlag]] = None) -> Regex[LProp, RProp]:
199
+ def regex(self, pattern: str, flags: Optional[re.RegexFlag | Iterable[re.RegexFlag]] = None) -> Regex:
140
200
  from ormlambda.sql.comparer import Regex
141
201
 
142
202
  if not isinstance(flags, Iterable):
@@ -148,7 +208,7 @@ class Column[TProp]:
148
208
  flags=flags,
149
209
  )
150
210
 
151
- def like[LProp, RProp](self, pattern: str) -> Like[LProp, RProp]:
211
+ def like(self, pattern: str) -> Like:
152
212
  from ormlambda.sql.comparer import Like
153
213
 
154
214
  return Like(self, pattern)
ormlambda/sql/comparer.py CHANGED
@@ -8,10 +8,11 @@ from ormlambda.common.interfaces.IQueryCommand import IQuery
8
8
  from ormlambda.sql.types import ConditionType, ComparerTypes
9
9
  from ormlambda.sql.clause_info import ClauseInfo
10
10
  from ormlambda import ConditionType as ConditionEnum
11
+ from ormlambda.sql.elements import Element
11
12
 
12
13
  if tp.TYPE_CHECKING:
13
14
  from ormlambda.sql.clause_info.clause_info_context import ClauseContextType
14
- from ormlambda.sql import Table
15
+ from ormlambda.dialects import Dialect
15
16
 
16
17
 
17
18
  class ICleaner(abc.ABC):
@@ -45,75 +46,88 @@ class CleanValue:
45
46
  return temp_name
46
47
 
47
48
 
48
- class Comparer[LTable: Table, LProp, RTable: Table, RProp](IQuery):
49
+ class Comparer(Element, IQuery):
50
+ __visit_name__ = "comparer"
51
+
49
52
  def __init__(
50
53
  self,
51
- left_condition: ConditionType[LProp],
52
- right_condition: ConditionType[RProp],
54
+ left_condition: ConditionType,
55
+ right_condition: ConditionType,
53
56
  compare: ComparerTypes,
54
57
  context: ClauseContextType = None,
55
58
  flags: tp.Optional[tp.Iterable[re.RegexFlag]] = None,
59
+ dialect: tp.Optional[Dialect] = None,
56
60
  ) -> None:
57
61
  self._context: ClauseContextType = context
58
62
  self._compare: ComparerTypes = compare
59
- self._left_condition: Comparer[LTable, LProp, RTable, RProp] | ClauseInfo[LTable] = left_condition
60
- self._right_condition: Comparer[LTable, LProp, RTable, RProp] | ClauseInfo[RTable] = right_condition
63
+ self._left_condition: Comparer | ClauseInfo = left_condition
64
+ self._right_condition: Comparer | ClauseInfo = right_condition
61
65
  self._flags = flags
66
+ self._dialect = dialect
62
67
 
63
68
  def set_context(self, context: ClauseContextType) -> None:
64
69
  self._context = context
70
+ return None
71
+
72
+ def set_dialect(self, dialect: Dialect) -> None:
73
+ self._dialect = dialect
74
+ return None
65
75
 
66
76
  def __repr__(self) -> str:
67
77
  return f"{Comparer.__name__}: {self.query}"
68
78
 
69
- def _create_clause_info[TTable](self, cond: ConditionType[LProp]) -> Comparer[LTable, LProp, RTable, RProp] | ClauseInfo[TTable]:
79
+ def _create_clause_info(self, cond: ConditionType, dialect: Dialect, **kw) -> Comparer | ClauseInfo:
70
80
  from ormlambda import Column
71
81
 
72
82
  if isinstance(cond, Comparer):
73
83
  return cond
74
- if isinstance(cond, Column):
75
- return ClauseInfo(cond.table, cond, alias_clause=None, context=self._context)
84
+ table = None if not isinstance(cond, Column) else cond.table
85
+
76
86
  # it a value that's not depend of any Table
77
- return ClauseInfo(None, cond, alias_clause=None, context=self._context)
87
+ return ClauseInfo(
88
+ table,
89
+ cond,
90
+ alias_clause=None,
91
+ context=self._context,
92
+ dialect=dialect,
93
+ **kw,
94
+ )
78
95
 
79
- @property
80
- def left_condition(self) -> Comparer | ClauseInfo[LTable]:
81
- return self._create_clause_info(self._left_condition)
96
+ def left_condition(self, dialect: Dialect) -> Comparer | ClauseInfo:
97
+ return self._create_clause_info(self._left_condition, dialect=dialect)
82
98
 
83
- @property
84
- def right_condition(self) -> Comparer | ClauseInfo[RTable]:
85
- return self._create_clause_info(self._right_condition)
99
+ def right_condition(self, dialect: Dialect) -> Comparer | ClauseInfo:
100
+ return self._create_clause_info(self._right_condition, dialect=dialect)
86
101
 
87
102
  @property
88
103
  def compare(self) -> ComparerTypes:
89
104
  return self._compare
90
105
 
91
- @property
92
- def query(self) -> str:
93
- lcond = self.left_condition.query
94
- rcond = self.right_condition.query
106
+ def query(self, dialect: Dialect, **kwargs) -> str:
107
+ lcond = self.left_condition(dialect).query(dialect, **kwargs)
108
+ rcond = self.right_condition(dialect).query(dialect, **kwargs)
95
109
 
96
110
  if self._flags:
97
111
  rcond = CleanValue(rcond, self._flags).clean()
98
112
 
99
113
  return f"{lcond} {self._compare} {rcond}"
100
114
 
101
- def __and__(self, other: Comparer, context: ClauseContextType = None) -> Comparer:
115
+ def __and__(self, other: Comparer, **kwargs) -> Comparer:
102
116
  # Customize the behavior of '&'
103
- return Comparer(self, other, "AND", context=context)
117
+ return Comparer(self, other, "AND", **kwargs)
104
118
 
105
- def __or__(self, other: Comparer, context: ClauseContextType = None) -> Comparer:
119
+ def __or__(self, other: Comparer, **kwargs) -> Comparer:
106
120
  # Customize the behavior of '|'
107
- return Comparer(self, other, "OR", context=context)
121
+ return Comparer(self, other, "OR", **kwargs)
108
122
 
109
123
  @classmethod
110
- def join_comparers(cls, comparers: list[Comparer], restrictive: bool = True, context: ClauseContextType = None) -> str:
124
+ def join_comparers(cls, comparers: list[Comparer], restrictive: bool = True, context: ClauseContextType = None, *, dialect) -> str:
111
125
  if not isinstance(comparers, tp.Iterable):
112
126
  raise ValueError(f"Excepted '{Comparer.__name__}' iterable not {type(comparers).__name__}")
113
127
  if len(comparers) == 1:
114
128
  comparer = comparers[0]
115
- comparer.set_context(context)
116
- return comparer.query
129
+ comparer._context = context
130
+ return comparer.query(dialect)
117
131
 
118
132
  join_method = cls.__or__ if not restrictive else cls.__and__
119
133
 
@@ -121,19 +135,19 @@ class Comparer[LTable: Table, LProp, RTable: Table, RProp](IQuery):
121
135
  for i in range(len(comparers) - 1):
122
136
  if ini_comparer is None:
123
137
  ini_comparer = comparers[i]
124
- ini_comparer.set_context(context)
138
+ ini_comparer._context = context
125
139
  right_comparer = comparers[i + 1]
126
- right_comparer.set_context(context)
127
- new_comparer = join_method(ini_comparer, right_comparer, context=context)
140
+ right_comparer._context = context
141
+ new_comparer = join_method(ini_comparer, right_comparer, context=context, dialect=dialect)
128
142
  ini_comparer = new_comparer
129
- return new_comparer.query
143
+ return new_comparer.query(dialect)
130
144
 
131
145
 
132
- class Regex[LProp, RProp](Comparer[None, LProp, None, RProp]):
146
+ class Regex(Comparer):
133
147
  def __init__(
134
148
  self,
135
- left_condition: ConditionType[LProp],
136
- right_condition: ConditionType[RProp],
149
+ left_condition: ConditionType,
150
+ right_condition: ConditionType,
137
151
  context: ClauseContextType = None,
138
152
  flags: tp.Optional[tp.Iterable[re.RegexFlag]] = None,
139
153
  ):
@@ -146,11 +160,11 @@ class Regex[LProp, RProp](Comparer[None, LProp, None, RProp]):
146
160
  )
147
161
 
148
162
 
149
- class Like[LProp, RProp](Comparer[None, LProp, None, RProp]):
163
+ class Like(Comparer):
150
164
  def __init__(
151
165
  self,
152
- left_condition: ConditionType[LProp],
153
- right_condition: ConditionType[RProp],
166
+ left_condition: ConditionType,
167
+ right_condition: ConditionType,
154
168
  context: ClauseContextType = None,
155
169
  ):
156
170
  super().__init__(left_condition, right_condition, ConditionEnum.LIKE.value, context)