ormlambda 2.7.2__tar.gz → 2.8.0__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.
Files changed (78) hide show
  1. {ormlambda-2.7.2 → ormlambda-2.8.0}/PKG-INFO +1 -1
  2. {ormlambda-2.7.2 → ormlambda-2.8.0}/pyproject.toml +1 -1
  3. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/interfaces/IStatements.py +31 -6
  4. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/__init__.py +1 -1
  5. {ormlambda-2.7.2/src/ormlambda/databases/my_sql/functions → ormlambda-2.8.0/src/ormlambda/databases/my_sql/clauses}/group_by.py +0 -2
  6. ormlambda-2.8.0/src/ormlambda/databases/my_sql/functions/__init__.py +5 -0
  7. ormlambda-2.8.0/src/ormlambda/databases/my_sql/functions/sum.py +39 -0
  8. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/statements.py +19 -7
  9. ormlambda-2.7.2/src/ormlambda/databases/my_sql/functions/__init__.py +0 -4
  10. {ormlambda-2.7.2 → ormlambda-2.8.0}/LICENSE +0 -0
  11. {ormlambda-2.7.2 → ormlambda-2.8.0}/README.md +0 -0
  12. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/__init__.py +0 -0
  13. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/__init__.py +0 -0
  14. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/abstract_classes/__init__.py +0 -0
  15. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/abstract_classes/abstract_model.py +0 -0
  16. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/abstract_classes/decomposition_query.py +0 -0
  17. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/abstract_classes/non_query_base.py +0 -0
  18. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/abstract_classes/query_base.py +0 -0
  19. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/enums/__init__.py +0 -0
  20. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/enums/condition_types.py +0 -0
  21. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/enums/join_type.py +0 -0
  22. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/interfaces/IAggregate.py +0 -0
  23. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/interfaces/IDecompositionQuery.py +0 -0
  24. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/interfaces/INonQueryCommand.py +0 -0
  25. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/interfaces/IQueryCommand.py +0 -0
  26. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/interfaces/IRepositoryBase.py +0 -0
  27. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/common/interfaces/__init__.py +0 -0
  28. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/__init__.py +0 -0
  29. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/delete/IDelete.py +0 -0
  30. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/delete/__init__.py +0 -0
  31. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/delete/abstract_delete.py +0 -0
  32. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/insert/IInsert.py +0 -0
  33. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/insert/__init__.py +0 -0
  34. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/insert/abstract_insert.py +0 -0
  35. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/update/IUpdate.py +0 -0
  36. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/update/__init__.py +0 -0
  37. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/update/abstract_update.py +0 -0
  38. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/upsert/IUpsert.py +0 -0
  39. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/upsert/__init__.py +0 -0
  40. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/upsert/abstract_upsert.py +0 -0
  41. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/where/__init__.py +0 -0
  42. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/components/where/abstract_where.py +0 -0
  43. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/__init__.py +0 -0
  44. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/__init__.py +0 -0
  45. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/count.py +0 -0
  46. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/create_database.py +0 -0
  47. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/delete.py +0 -0
  48. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/drop_database.py +0 -0
  49. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/drop_table.py +0 -0
  50. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/insert.py +0 -0
  51. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/joins.py +0 -0
  52. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/limit.py +0 -0
  53. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/offset.py +0 -0
  54. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/order.py +0 -0
  55. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/select.py +0 -0
  56. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/update.py +0 -0
  57. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/upsert.py +0 -0
  58. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/clauses/where_condition.py +0 -0
  59. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/functions/concat.py +0 -0
  60. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/functions/max.py +0 -0
  61. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/functions/min.py +0 -0
  62. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/databases/my_sql/repository.py +0 -0
  63. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/model_base.py +0 -0
  64. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/__init__.py +0 -0
  65. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/column.py +0 -0
  66. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/dtypes.py +0 -0
  67. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/foreign_key.py +0 -0
  68. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/lambda_disassembler/__init__.py +0 -0
  69. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/lambda_disassembler/dis_types.py +0 -0
  70. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/lambda_disassembler/disassembler.py +0 -0
  71. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/lambda_disassembler/dtypes.py +0 -0
  72. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/lambda_disassembler/name_of.py +0 -0
  73. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/lambda_disassembler/nested_element.py +0 -0
  74. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/lambda_disassembler/tree_instruction.py +0 -0
  75. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/module_tree/__init__.py +0 -0
  76. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/module_tree/dfs_traversal.py +0 -0
  77. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/module_tree/dynamic_module.py +0 -0
  78. {ormlambda-2.7.2 → ormlambda-2.8.0}/src/ormlambda/utils/table_constructor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ormlambda
3
- Version: 2.7.2
3
+ Version: 2.8.0
4
4
  Summary: ORM designed to interact with the database (currently with MySQL) using lambda functions and nested functions
5
5
  Author: p-hzamora
6
6
  Author-email: p.hzamora@icloud.com
@@ -3,7 +3,7 @@ line-length = 320
3
3
 
4
4
  [tool.poetry]
5
5
  name = "ormlambda"
6
- version = "2.7.2"
6
+ version = "2.8.0"
7
7
  description = "ORM designed to interact with the database (currently with MySQL) using lambda functions and nested functions"
8
8
  authors = ["p-hzamora <p.hzamora@icloud.com>"]
9
9
  readme = "README.md"
@@ -91,7 +91,12 @@ class IStatements[T: Table](ABC):
91
91
  # endregion
92
92
  # region count
93
93
  @abstractmethod
94
- def count(self, selection: Callable[[T], property]) -> int: ...
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](self, column: Callable[[T], TProp], alias: bool = True, alias_name: str = "max") -> TProp: ...
166
- @overload
167
- def min[TProp](self, column: Callable[[T], TProp], alias: bool = True, alias_name: str = "min") -> TProp: ...
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], select_query: Callable[[T], tuple[*Ts]]) -> tuple[tuple[*Ts]]: ...
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 ..functions.group_by import GroupBy as GroupBy
16
+ from .group_by import GroupBy as GroupBy
@@ -25,8 +25,6 @@ class GroupBy[T: tp.Type[Table], TProp](DecompositionQueryBase[T], IAggregate[T]
25
25
  by=by,
26
26
  )
27
27
 
28
- self._column: TProp = column
29
-
30
28
  def alias_children_resolver[Tclause: tp.Type[Table]](self, clause_info: ClauseInfo[Tclause]):
31
29
  return None
32
30
 
@@ -0,0 +1,5 @@
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(self, selection: Callable[[T], tuple] = lambda x: "*") -> int:
132
- count_select: IQuery = Select[T](self._model, lambda x: Count[T](self._model, selection))
133
- self._query_list["select"].append(count_select)
134
- query = self._build()
135
- return self.repository.read_sql(query)[0][0]
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[TRepo, *Ts](self, column: Callable[[T], TRepo], select_query: Callable[[T], tuple[*Ts]]) -> tuple[tuple[*Ts]]:
215
- return GroupBy[T, TRepo, tuple[*Ts]](self._model, column, select_query)
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:
@@ -1,4 +0,0 @@
1
- from .max import Max # noqa: F401
2
- from .min import Min # noqa: F401
3
- from .concat import Concat # noqa: F401
4
- from .group_by import GroupBy # noqa: F401
File without changes
File without changes