ormlambda 2.7.2__py3-none-any.whl → 2.8.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.
- ormlambda/common/interfaces/IStatements.py +31 -6
- ormlambda/databases/my_sql/clauses/__init__.py +1 -1
- ormlambda/databases/my_sql/{functions → clauses}/group_by.py +0 -2
- ormlambda/databases/my_sql/functions/__init__.py +5 -4
- ormlambda/databases/my_sql/functions/sum.py +39 -0
- ormlambda/databases/my_sql/statements.py +19 -7
- {ormlambda-2.7.2.dist-info → ormlambda-2.8.0.dist-info}/METADATA +1 -1
- {ormlambda-2.7.2.dist-info → ormlambda-2.8.0.dist-info}/RECORD +10 -9
- {ormlambda-2.7.2.dist-info → ormlambda-2.8.0.dist-info}/LICENSE +0 -0
- {ormlambda-2.7.2.dist-info → ormlambda-2.8.0.dist-info}/WHEEL +0 -0
@@ -91,7 +91,12 @@ class IStatements[T: Table](ABC):
|
|
91
91
|
# endregion
|
92
92
|
# region count
|
93
93
|
@abstractmethod
|
94
|
-
def count(
|
94
|
+
def count(
|
95
|
+
self,
|
96
|
+
selection: Callable[[T], property],
|
97
|
+
alias: bool = ...,
|
98
|
+
alias_name: Optional[str] = ...,
|
99
|
+
) -> int: ...
|
95
100
|
|
96
101
|
# endregion
|
97
102
|
# region delete
|
@@ -162,10 +167,30 @@ class IStatements[T: Table](ABC):
|
|
162
167
|
# endregion
|
163
168
|
# region max
|
164
169
|
@overload
|
165
|
-
def max[TProp](
|
166
|
-
|
167
|
-
|
168
|
-
|
170
|
+
def max[TProp](
|
171
|
+
self,
|
172
|
+
column: Callable[[T], TProp],
|
173
|
+
alias: bool = ...,
|
174
|
+
alias_name: Optional[str] = ...,
|
175
|
+
) -> TProp: ...
|
176
|
+
# endregion
|
177
|
+
# region min
|
178
|
+
@overload
|
179
|
+
def min[TProp](
|
180
|
+
self,
|
181
|
+
column: Callable[[T], TProp],
|
182
|
+
alias: bool = ...,
|
183
|
+
alias_name: Optional[str] = ...,
|
184
|
+
) -> TProp: ...
|
185
|
+
# endregion
|
186
|
+
# region sum
|
187
|
+
@overload
|
188
|
+
def sum[TProp](
|
189
|
+
self,
|
190
|
+
column: Callable[[T], TProp],
|
191
|
+
alias: bool = ...,
|
192
|
+
alias_name: Optional[str] = ...,
|
193
|
+
) -> TProp: ...
|
169
194
|
# endregion
|
170
195
|
# region select
|
171
196
|
@overload
|
@@ -231,7 +256,7 @@ class IStatements[T: Table](ABC):
|
|
231
256
|
# endregion
|
232
257
|
# region group_by
|
233
258
|
@abstractmethod
|
234
|
-
def group_by[TRepo, *Ts](self, column: Callable[[T], TRepo]
|
259
|
+
def group_by[TRepo, *Ts](self, column: Callable[[T], TRepo]) -> IStatements[T]: ...
|
235
260
|
|
236
261
|
# endregion
|
237
262
|
|
@@ -13,4 +13,4 @@ from .update import UpdateQuery as UpdateQuery
|
|
13
13
|
from .upsert import UpsertQuery as UpsertQuery
|
14
14
|
from .where_condition import WhereCondition as WhereCondition
|
15
15
|
from .count import Count as Count
|
16
|
-
from
|
16
|
+
from .group_by import GroupBy as GroupBy
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from .max import Max
|
2
|
-
from .min import Min
|
3
|
-
from .concat import Concat
|
4
|
-
from .group_by import GroupBy
|
1
|
+
from .max import Max as Max
|
2
|
+
from .min import Min as Min
|
3
|
+
from .concat import Concat as Concat
|
4
|
+
from ..clauses.group_by import GroupBy as GroupBy
|
5
|
+
from .sum import Sum as Sum
|
@@ -0,0 +1,39 @@
|
|
1
|
+
from ormlambda.common.interfaces import IAggregate
|
2
|
+
import typing as tp
|
3
|
+
|
4
|
+
from ormlambda.common.abstract_classes.decomposition_query import DecompositionQueryBase, ClauseInfo
|
5
|
+
|
6
|
+
if tp.TYPE_CHECKING:
|
7
|
+
from ormlambda import Table
|
8
|
+
|
9
|
+
|
10
|
+
class Sum[T: tp.Type[Table]](DecompositionQueryBase[T], IAggregate[T]):
|
11
|
+
NAME: str = "SUM"
|
12
|
+
|
13
|
+
@tp.overload
|
14
|
+
def __init__[T: tp.Type[Table]](self, table: T, column: tp.Callable[[T], tp.Any], *, alias: bool = True, alias_name: str = ...) -> None: ...
|
15
|
+
|
16
|
+
def __init__(
|
17
|
+
self,
|
18
|
+
table: T,
|
19
|
+
column: str | tp.Callable[[T], tuple],
|
20
|
+
*,
|
21
|
+
alias: bool = True,
|
22
|
+
alias_name: str = "sum",
|
23
|
+
) -> None:
|
24
|
+
super().__init__(
|
25
|
+
table,
|
26
|
+
lambda_query=column,
|
27
|
+
alias=alias,
|
28
|
+
alias_name=alias_name,
|
29
|
+
)
|
30
|
+
|
31
|
+
def alias_children_resolver[Tclause: tp.Type[Table]](self, clause_info: ClauseInfo[Tclause]):
|
32
|
+
if isinstance(clause_info._row_column, IAggregate):
|
33
|
+
return clause_info._row_column.alias
|
34
|
+
return None
|
35
|
+
|
36
|
+
@property
|
37
|
+
def query(self) -> str:
|
38
|
+
col = ", ".join([x.query for x in self.all_clauses])
|
39
|
+
return f"{self.NAME}({col})"
|
@@ -128,11 +128,13 @@ class MySQLStatements[T: Table](AbstractSQLStatements[T, MySQLConnection]):
|
|
128
128
|
return self
|
129
129
|
|
130
130
|
@override
|
131
|
-
def count(
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
131
|
+
def count(
|
132
|
+
self,
|
133
|
+
selection: Callable[[T], tuple] = lambda x: "*",
|
134
|
+
alias=True,
|
135
|
+
alias_name=None,
|
136
|
+
) -> IQuery:
|
137
|
+
return Count[T](self._model, selection, alias=alias, alias_name=alias_name)
|
136
138
|
|
137
139
|
@override
|
138
140
|
def join(self, table_left: Table, table_right: Table, *, by: str) -> IStatements_two_generic[T, MySQLConnection]:
|
@@ -172,6 +174,10 @@ class MySQLStatements[T: Table](AbstractSQLStatements[T, MySQLConnection]):
|
|
172
174
|
def min[TProp](self, column: Callable[[T], TProp], alias: bool = True, alias_name: str = "min") -> TProp:
|
173
175
|
return func.Min[T](self._model, column=column, alias=alias, alias_name=alias_name)
|
174
176
|
|
177
|
+
@override
|
178
|
+
def sum[TProp](self, column: Callable[[T], TProp], alias: bool = True, alias_name: str = "sum") -> TProp:
|
179
|
+
return func.Sum[T](self._model, column=column, alias=alias, alias_name=alias_name)
|
180
|
+
|
175
181
|
@override
|
176
182
|
def select[TValue, TFlavour, *Ts](self, selector: Optional[Callable[[T], tuple[TValue, *Ts]]] = lambda: None, *, flavour: Optional[Type[TFlavour]] = None, by: JoinType = JoinType.INNER_JOIN):
|
177
183
|
if len(inspect.signature(selector).parameters) == 0:
|
@@ -211,8 +217,14 @@ class MySQLStatements[T: Table](AbstractSQLStatements[T, MySQLConnection]):
|
|
211
217
|
return tuple([res[0] for res in response])
|
212
218
|
|
213
219
|
@override
|
214
|
-
def group_by[
|
215
|
-
|
220
|
+
def group_by[*Ts](self, column: str | Callable[[T], Any]) -> IStatements_two_generic[T, MySQLConnection]:
|
221
|
+
if isinstance(column, str):
|
222
|
+
groupby = GroupBy[T, tuple[*Ts]](self._model, lambda x: column)
|
223
|
+
else:
|
224
|
+
groupby = GroupBy[T, tuple[*Ts]](self._model, column)
|
225
|
+
# Only can be one LIMIT SQL parameter. We only use the last LimitQuery
|
226
|
+
self._query_list["group by"].append(groupby)
|
227
|
+
return self
|
216
228
|
|
217
229
|
@override
|
218
230
|
def _build(self) -> str:
|
@@ -13,7 +13,7 @@ ormlambda/common/interfaces/IDecompositionQuery.py,sha256=dHdCxezbWwy-c4U4po2hQB
|
|
13
13
|
ormlambda/common/interfaces/INonQueryCommand.py,sha256=7CjLW4sKqkR5zUIGvhRXOtzTs6vypJW1a9EJHlgCw2c,260
|
14
14
|
ormlambda/common/interfaces/IQueryCommand.py,sha256=hfzCosK4-n8RJIb2PYs8b0qU3TNmfYluZXBf47KxxKs,331
|
15
15
|
ormlambda/common/interfaces/IRepositoryBase.py,sha256=zGm7tDrFLKj3FMYN-MWI-em3INws27g2yByNYYMx0qk,1126
|
16
|
-
ormlambda/common/interfaces/IStatements.py,sha256=
|
16
|
+
ormlambda/common/interfaces/IStatements.py,sha256=df3pGRFSwyBcFct0ntMy8E9RNCHreXTO-qirdetS05M,10674
|
17
17
|
ormlambda/common/interfaces/__init__.py,sha256=00ca9a-u_A8DzyEyxPfBMxfqLKFzzUgJaeNmoRitAbA,360
|
18
18
|
ormlambda/components/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
19
|
ormlambda/components/delete/IDelete.py,sha256=06ZEdbKBxsHSwsGMBu0E1om4WJjojZAm-L3b95eQrcc,139
|
@@ -32,12 +32,13 @@ ormlambda/components/where/__init__.py,sha256=mI-ylB6cTTVf3rtCX54apgZrMP6y9tTD7-
|
|
32
32
|
ormlambda/components/where/abstract_where.py,sha256=93tIJBC81OUUVV6il7mISibBwqJeodQdFFQ9DShDKOQ,344
|
33
33
|
ormlambda/databases/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
34
34
|
ormlambda/databases/my_sql/__init__.py,sha256=3PbOp4WqxJzFOSRwBozqyNtQi25cLLdiJFPDzEnSI70,115
|
35
|
-
ormlambda/databases/my_sql/clauses/__init__.py,sha256=
|
35
|
+
ormlambda/databases/my_sql/clauses/__init__.py,sha256=F7p---sNQBefi_dgydV6Wp1YuOwDzvSQOdbcjWtBi2k,767
|
36
36
|
ormlambda/databases/my_sql/clauses/count.py,sha256=UFJD-ELp-xvOyPbvYX37GvRZsP8M_axambnI7_h91yA,1177
|
37
37
|
ormlambda/databases/my_sql/clauses/create_database.py,sha256=WnWaAuhxeE71NZKXW37WZ-msRqjum7TFCSRK1IGdSTE,1279
|
38
38
|
ormlambda/databases/my_sql/clauses/delete.py,sha256=nUKNQgwF5YUfzk2icWpecYjrGk5DeXpp7eiwtWCf_3c,1924
|
39
39
|
ormlambda/databases/my_sql/clauses/drop_database.py,sha256=nMM0YUbcH0D9X3bU70Uc6S_dsIrAZy-IrYuIKrQZNrg,505
|
40
40
|
ormlambda/databases/my_sql/clauses/drop_table.py,sha256=meX4e-pVPQ7UwlPSHV5e9HHRblI1BlkLSc7ssl8WUiI,592
|
41
|
+
ormlambda/databases/my_sql/clauses/group_by.py,sha256=xG8YhdaDWBm99EFMkzCsBJNhHOJy5lvXmpaHu3jClro,1042
|
41
42
|
ormlambda/databases/my_sql/clauses/insert.py,sha256=LO9H8VVK3j62dICXqpEUXKxOHPxkD1LGvogmDq2zmho,2805
|
42
43
|
ormlambda/databases/my_sql/clauses/joins.py,sha256=U6JnUvQo7AXyEeK-X1jMvckXefgAB7ugSmJCZhH1XQI,3058
|
43
44
|
ormlambda/databases/my_sql/clauses/limit.py,sha256=a4lI8FVRKpfXwBQTXdkbVtlQkmzcjE20ymiCy1IaSc4,391
|
@@ -47,13 +48,13 @@ ormlambda/databases/my_sql/clauses/select.py,sha256=unJBteFK5D360KnIPyqz8OMaVJqX
|
|
47
48
|
ormlambda/databases/my_sql/clauses/update.py,sha256=3Htw0_PT3EckEiF214-V2r63lcNoRBroKZI9yg48Ddg,1867
|
48
49
|
ormlambda/databases/my_sql/clauses/upsert.py,sha256=eW2pQ4ax-GKuXiaWKoSRSS1GrHuILJBsmj83ADbBQ34,1951
|
49
50
|
ormlambda/databases/my_sql/clauses/where_condition.py,sha256=UgU5vnTqFAx91wKwnECpww5tETDZ9F7IdC_SiZOgZhI,8336
|
50
|
-
ormlambda/databases/my_sql/functions/__init__.py,sha256=
|
51
|
+
ormlambda/databases/my_sql/functions/__init__.py,sha256=hA8t3mUpV2p-pO4TVp5rjC5Yp7aIkWPsS8NpLi3DUh0,171
|
51
52
|
ormlambda/databases/my_sql/functions/concat.py,sha256=cZztl5eSATpYMKVKfyPbul6OocaUkaEGpt3uWmhf-3o,1177
|
52
|
-
ormlambda/databases/my_sql/functions/group_by.py,sha256=ym1L6RBA70hmzrkJ-IA_-6Esq7eoVgNdf1vWpqxRq-8,1080
|
53
53
|
ormlambda/databases/my_sql/functions/max.py,sha256=zrO_RBKsHhyokEmSpPI6Yg5OY6Jf4GGp2RveBJdOuuA,1190
|
54
54
|
ormlambda/databases/my_sql/functions/min.py,sha256=SEVuUdIJNz9zM5za1kLTWalFkhErjsjyBb8SU8n0F94,1190
|
55
|
+
ormlambda/databases/my_sql/functions/sum.py,sha256=akKYr2dI8TZS5MDvybfHn_idhPOvEH0cj6mDRQIHe-M,1188
|
55
56
|
ormlambda/databases/my_sql/repository.py,sha256=fSAAmO_T5mC1bodOVZn5CY9JSfRq4VhsdlWT1JLl7Zw,6927
|
56
|
-
ormlambda/databases/my_sql/statements.py,sha256=
|
57
|
+
ormlambda/databases/my_sql/statements.py,sha256=inUEyLUl3Z6TxE7PpJUWw0SZBoO_JbnrS_XL_wCyHn4,11873
|
57
58
|
ormlambda/model_base.py,sha256=RrAATQWX_bHJ0ZQ5sCHyJKA4NiR7ZJY4I6dqhnGWWAc,1216
|
58
59
|
ormlambda/utils/__init__.py,sha256=ywMdWqmA2jHj19-W-S04yfaYF5hv4IZ1lZDq0B8Jnjs,142
|
59
60
|
ormlambda/utils/column.py,sha256=5FAGzCU4yvNS4MhwJJ5i73h7RvHD5UCVox0NdzMsMiE,1945
|
@@ -70,7 +71,7 @@ ormlambda/utils/module_tree/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
70
71
|
ormlambda/utils/module_tree/dfs_traversal.py,sha256=lSF03G63XtJFLp03ueAmsHMBvhUkjptDbK3IugXm8iU,1425
|
71
72
|
ormlambda/utils/module_tree/dynamic_module.py,sha256=zwvjU3U2cz6H2CDp9Gncs5D5bSAyfITNa2SDqFDl8rw,8551
|
72
73
|
ormlambda/utils/table_constructor.py,sha256=8Apm44K6MiYMK3PQyK74MUV18OatbFI9eDLAVklQO0w,11660
|
73
|
-
ormlambda-2.
|
74
|
-
ormlambda-2.
|
75
|
-
ormlambda-2.
|
76
|
-
ormlambda-2.
|
74
|
+
ormlambda-2.8.0.dist-info/LICENSE,sha256=xBprFw8GJLdHMOoUqDk0427EvjIcbEREvXXVFULuuXU,1080
|
75
|
+
ormlambda-2.8.0.dist-info/METADATA,sha256=HV3vUXqD2StgsPEk4VwRtPLp44DRjIUgSoMTRsWAkNw,8428
|
76
|
+
ormlambda-2.8.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
77
|
+
ormlambda-2.8.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|