ormlambda 2.11.2__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 -319
  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.2.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.2.dist-info/RECORD +0 -81
  117. /ormlambda/{utils → sql}/dtypes.py +0 -0
  118. {ormlambda-2.11.2.dist-info → ormlambda-3.7.0.dist-info}/LICENSE +0 -0
  119. {ormlambda-2.11.2.dist-info → ormlambda-3.7.0.dist-info}/WHEEL +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ormlambda
3
- Version: 2.11.2
3
+ Version: 3.7.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
@@ -9,6 +9,7 @@ Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.12
10
10
  Requires-Dist: fluent-validation (==4.3.1)
11
11
  Requires-Dist: mysql-connector-python (>=9.0.0,<10.0.0)
12
+ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
12
13
  Requires-Dist: shapely (>=2.0.6,<3.0.0)
13
14
  Description-Content-Type: text/markdown
14
15
 
@@ -36,9 +37,17 @@ database = MySQLRepository(user=USERNAME, password=PASSWORD, database="sakila",
36
37
 
37
38
  ## Select all columns
38
39
  ```python
39
- from models.address import AddressModel
40
+ from ormlambda import ORM
41
+ from ormlambda.databases.my_sql import MySQLRepository
42
+
43
+ from models.address import Address
44
+ from config import config_dict
45
+
46
+ db = MySQLRepository(**config_dict)
47
+
48
+ AddressModel = ORM(Address,db)
40
49
 
41
- result = AddressModel(database).select()
50
+ result = AddressModel.select()
42
51
  ```
43
52
  The `result` var will be of type `tuple[Address, ...]`
44
53
 
@@ -46,11 +55,13 @@ The `result` var will be of type `tuple[Address, ...]`
46
55
  Once the `AddressModel` class is created, we will not only be able to access all the information in that table, but also all the information in all the tables that have foreign keys related to it."
47
56
 
48
57
  ```python
49
- from ormlambda import ConditionType
50
- from models.address import AddressModel
58
+ from models.address import Address
51
59
 
60
+ db = MySQLRepository(**config_dict)
52
61
 
53
- result = AddressModel(database).where(lambda x: (x.City.Country, ConditionType.REGEXP, r"^[aA]")).select(
62
+ AddressModel = ORM(Address,db)
63
+
64
+ result = AddressModel.where(Address.City.Country.country.regex(r"^[aA]")).select(
54
65
  lambda address: (
55
66
  address,
56
67
  address.City,
@@ -64,31 +75,51 @@ If we were used `select_one` method, we retrieved `tuple[Address, City, Country]
64
75
 
65
76
  ## Filter by `where` condition
66
77
 
78
+ we can use only the Original Table to pass the variables like
67
79
  ```python
68
- result = AddressModel(database).where(lambda x: 10 <= x.address_id <= 30).select()
80
+ result = AddressModel.where(
81
+ [
82
+ Address.address_id >= 10,
83
+ Address.address_id <= 30,
84
+ ]
85
+ ).select()
69
86
  ```
87
+ Or by using a lambda function that returns an iterable for tables where the name is unusually long.
88
+
89
+ ```python
90
+ result = AddressModel.where(
91
+ lambda x: [
92
+ x.address_id >= 10,
93
+ x.address_id <= 30,
94
+ ]
95
+ ).select()
70
96
 
97
+ ```
71
98
  Additionally, we can filter by others tables. For example, we can return all addresses for each city where `country_id` = 87 (Spain)
72
99
 
73
100
  ```python
74
- result = AddressModel(database).where(lambda x: x.City.Country.country_id == 87).select()
101
+ result = AddressModel.where(Address.City.Country.country_id == 87).select()
75
102
  ```
76
103
 
77
104
  We can also return `Address`, `City` or `Country` if needed.
78
105
 
79
106
  ```python
80
- result = AddressModel(database).where(lambda x: x.City.Country.country_id == 87).select(lambda x: (x, x.City, x.City.Country))
107
+ result = AddressModel.where(Address.City.Country.country_id == 87).select(lambda x: (x, x.City, x.City.Country))
81
108
  ```
82
109
 
83
110
  ### Pass variables to the `where` method
84
- Since we generally work with lambda methods, I often have to work with `bytecode` to retrieve the name of the string variables. For this reason, it's imperative that we map these variables to replace them with the actual values.
85
-
86
111
  ```python
87
112
  LOWER = 10
88
113
  UPPER = 30
89
- AddressModel(database).where(lambda x: LOWER <= x.address_id <= UPPER, LOWER=LOWER, UPPER=UPPER).select()
114
+
115
+ AddressModel.where(
116
+ [
117
+ Address.address_id >= LOWER,
118
+ Address.address_id <= UPPER,
119
+ ]
120
+ ).select()
90
121
  ```
91
- That solution is somewhat `awkward` and not very clean, but it's necessary for automating queries.
122
+
92
123
 
93
124
  ## Writable methods INSERT, UPDATE, DELETE
94
125
  The easiest way to add or delete data in your database is by using its appropiate methods. You just need to instantiate an object with the data and pass it to the method
@@ -97,22 +128,21 @@ The easiest way to add or delete data in your database is by using its appropiat
97
128
  ```python
98
129
  address = Address(address_id=1, address="C/ ...", phone="XXXXXXXXX", postal_code="28026")
99
130
 
100
- AddressModel(database).insert(address)
131
+ AddressModel.insert(address)
101
132
  ```
102
133
 
103
134
  ### Update
104
-
105
135
  You can use either the properties of the same object or `str` values.
106
136
  ```python
107
137
 
108
- AddressModel(database).where(lambda x: x.address_id == 1).update(
138
+ AddressModel.where(lambda x: x.address_id == 1).update(
109
139
  {
110
140
  Address.phone: "YYYYYYYYY",
111
141
  Address.postal_code: "28030",
112
142
  }
113
143
  )
114
144
 
115
- AddressModel(database).where(lambda x: x.address_id == 1).update(
145
+ AddressModel.where(lambda x: x.address_id == 1).update(
116
146
  {
117
147
  "phone": "YYYYYYYYY",
118
148
  "postal_code": "28030",
@@ -122,7 +152,7 @@ AddressModel(database).where(lambda x: x.address_id == 1).update(
122
152
  ### Delete
123
153
 
124
154
  ```python
125
- AddressModel(database).where(lambda x: x.address_id == 1).delete()
155
+ AddressModel.where(lambda x: x.address_id == 1).delete()
126
156
  ```
127
157
 
128
158
 
@@ -139,67 +169,46 @@ The easiest way to map your tables is:
139
169
 
140
170
  ```python
141
171
  from datetime import datetime
142
-
143
172
  from ormlambda import (
144
- Column,
145
173
  Table,
146
- BaseModel,
174
+ Column,
147
175
  ForeignKey,
148
176
  )
149
- from ormlambda.common.interfaces import IStatements_two_generic, IRepositoryBase
150
-
151
177
 
152
178
  class Country(Table):
153
179
  __table_name__ = "country"
154
180
 
155
- country_id: int = Column[int](is_primary_key=True)
156
- country: str
157
- last_update: datetime
158
-
159
-
160
- class Address(Table):
161
- __table_name__ = "address"
162
-
163
- address_id: int = Column[int](is_primary_key=True)
164
- address: str
165
- address2: str
166
- district: str
167
- city_id: int
168
- postal_code: str
169
- phone: str
170
- location: str
171
- last_update: datetime = Column[datetime](is_auto_generated=True)
172
-
173
- City = ForeignKey["Address", City](__table_name__, City, lambda a, c: a.city_id == c.city_id)
181
+ country_id: Column[int] = Column(int, is_primary_key=True)
182
+ country: Column[str]
183
+ last_update: Column[datetime]
174
184
 
175
185
 
176
186
  class City(Table):
177
187
  __table_name__ = "city"
178
188
 
179
- city_id: int = Column[int](is_primary_key=True)
180
- city: str
181
- country_id: int
182
- last_update: datetime
183
-
184
- Country = ForeignKey["City", Country](__table_name__, Country, lambda ci, co: ci.country_id == co.country_id)
185
- ```
189
+ city_id: Column[int] = Column(int, is_primary_key=True)
190
+ city: Column[str]
191
+ country_id: Column[int]
192
+ last_update: Column[datetime]
186
193
 
187
- Once created, you need to create a Model for each Table
194
+ Country = ForeignKey["City", Country](Country, lambda ci, co: ci.country_id == co.country_id)
188
195
 
189
- ```python
190
- class CountryModel(BaseModel[Country]):
191
- def __new__[TRepo](cls, repository: IRepositoryBase[TRepo]):
192
- return super().__new__(cls, Country, repository)
193
196
 
197
+ class Address(Table):
198
+ __table_name__ = "address"
194
199
 
195
- class AddressModel(BaseModel[Address]):
196
- def __new__[TRepo](cls, repository: IRepositoryBase[TRepo]):
197
- return super().__new__(cls, Address, repository)
200
+ address_id: Column[int] = Column(int, is_primary_key=True)
201
+ address: Column[str]
202
+ address2: Column[str]
203
+ district: Column[str]
204
+ city_id: Column[int]
205
+ postal_code: Column[str]
206
+ phone: Column[str]
207
+ location: Column[str]
208
+ last_update: Column[datetime] = Column(datetime, is_auto_generated=True)
198
209
 
210
+ City = ForeignKey["Address", City](City, lambda a, c: a.city_id == c.city_id)
199
211
 
200
- class CityModel(BaseModel[City]):
201
- def __new__[TRepo](cls, repository: IRepositoryBase[TRepo]):
202
- return super().__new__(cls, City, repository)
203
212
  ```
204
213
 
205
214
  # Creating complex queries with lambda
@@ -211,10 +220,10 @@ To retrieve all `Address` object where the fk reference to the `City` table, and
211
220
 
212
221
  ```python
213
222
  result = (
214
- AddressModel(database)
223
+ AddressModel
215
224
  .order(lambda a: a.address_id, order_type="DESC")
216
225
  .where(lambda x: x.City.Country.country_id >= 50)
217
- .select(lambda a: (a))
226
+ .select(Address)
218
227
  )
219
228
 
220
229
  ```
@@ -223,9 +232,9 @@ Also you can use `ConditionType` enum for `regular expressions` and get, for exa
223
232
 
224
233
  ```python
225
234
  address, city, country = (
226
- AddressModel(database)
227
- .order(lambda a: a.address_id, order_type="DESC")
228
- .where(lambda x: (x.City.Country, ConditionType.REGEXP, r"^[A]"))
235
+ AddressModel
236
+ .order(Address.address_id, order_type="DESC")
237
+ .where(Address.City.Country.country.regex(r"^[A]"))
229
238
  .limit(100)
230
239
  .select(
231
240
  lambda a: (
@@ -238,7 +247,6 @@ address, city, country = (
238
247
 
239
248
 
240
249
  for a in address:
241
-
242
250
  print(a.address_id)
243
251
 
244
252
  for c in city:
@@ -253,8 +261,7 @@ In the example above, we see that the `result` var returns a tuple of tuples. Ho
253
261
 
254
262
  ```python
255
263
  result = (
256
- a_model
257
- .where(lambda x: (x.City.Country, ConditionType.REGEXP, r"^[A]"))
264
+ AddressModel.where(Address.City.Country.country.regex(r"^[A]"))
258
265
  .limit(100)
259
266
  .select(
260
267
  lambda a: (
@@ -270,4 +277,61 @@ result = (
270
277
 
271
278
  with this approach, we will obtain a dictionary where the key will be the concatenation between the selected table name and the column name specified in the lambda function, to avoid overwritting data from tables that sharing column names.
272
279
 
280
+ # Other methods
273
281
 
282
+ ## max
283
+ ```python
284
+ res = AddressModel.max(Address.address_id, execute=True)
285
+ ```
286
+ ## min
287
+ ```python
288
+ res = AddressModel.min(Address.address_id, execute=True)
289
+ ```
290
+ ## sum
291
+ ```python
292
+ res = AddressModel.sum(Address.address_id, execute=True)
293
+ ```
294
+ ## count
295
+ ```python
296
+ res = AddressModel.count(Address.address_id, execute=True)
297
+ ```
298
+
299
+ ## Combine aggregation method
300
+ As shown in the previous examples, setting the `execute` attribute to `True` allows us to perform the corresponding query in a single line. However, if you're looking to improve efficiency, you can combine all of them into one query.
301
+ ```python
302
+ result = AddressModel.select_one(
303
+ lambda x: (
304
+ AddressModel.min(x.address_id),
305
+ AddressModel.max(x.address_id),
306
+ AddressModel.count(x.address_id),
307
+ ),flavour=dict
308
+ )
309
+ ```
310
+ Getting something like
311
+
312
+ ```python
313
+ # {
314
+ # "min": 1,
315
+ # "max": 605,
316
+ # "count": 603,
317
+ # }
318
+ ```
319
+
320
+ You also can use custom alias for each method
321
+
322
+ ```python
323
+ AddressModel.select_one(
324
+ lambda x: (
325
+ AddressModel.min(x.address_id),
326
+ AddressModel.max(x.address_id, alias="custom-max"),
327
+ AddressModel.count(x.address_id),
328
+ ),
329
+ flavour=dict,
330
+ )
331
+
332
+ # {
333
+ # "min": 1,
334
+ # "custom-max": 605,
335
+ # "count": 603,
336
+ # }
337
+ ```
@@ -0,0 +1,117 @@
1
+ ormlambda/__init__.py,sha256=KGnAPj90RWKP1GnuSQD1rAaREXfE2pwzg7vCTYB36ZI,619
2
+ ormlambda/caster/__init__.py,sha256=JWJ6qdPTk_uyJHGfFpvFCZeOXdP6DzL4-MtMFZVDPRY,150
3
+ ormlambda/caster/base_caster.py,sha256=ogihKXZIyeDsJ2N0EDKujf6BIfVSJAZ9G1jIbBXJV2o,1786
4
+ ormlambda/caster/caster.py,sha256=ecDvGgMI3yFtJxqKD9XcSVtBcqQtYitfMTooWPlLnEY,1885
5
+ ormlambda/caster/interfaces/ICaster.py,sha256=MCBBVBho9KH67vCcUk8nclY0a7QoqxgdyVJJR0-QDT0,759
6
+ ormlambda/caster/interfaces/__init__.py,sha256=TRoIxxgxuhUhCJq2ldLS3UEa1THrMXEIyTH5K46vyGw,43
7
+ ormlambda/common/__init__.py,sha256=g4yGxH4WEgvQ7Rix4lpp3FQ-3SeRhptNd5sabgZLQNk,59
8
+ ormlambda/common/abstract_classes/__init__.py,sha256=l39_WaBH38wrDV2KXb83c73ct7oxSIIVj2Ep4UcvxrU,186
9
+ ormlambda/common/abstract_classes/decomposition_query.py,sha256=CH4rRIH_wQCkpDA2qWOdzf-c5BCX6F_2bkpMPjNB044,7592
10
+ ormlambda/common/abstract_classes/non_query_base.py,sha256=1BQa9n14k7A2txmnj76nBZckJXARFcJIRooT7VR6y3Q,991
11
+ ormlambda/common/abstract_classes/query_base.py,sha256=6qUFPwsVx45kUW3b66pHiSyjhcH4mzbdkddlGeUnG7c,266
12
+ ormlambda/common/enums/__init__.py,sha256=4lVKCHi1JalwgNzjsAXqX-C54NJEH83y2v5baMO8fN4,103
13
+ ormlambda/common/enums/condition_types.py,sha256=QZnhhlTwzLcZ9kkmG6a08fQjUUJsJ5XGAH7QCiJRL1A,330
14
+ ormlambda/common/enums/join_type.py,sha256=EosZVnvAc72LlZHuICIgoKWwUJzhvWOIIAohcbDYPQo,354
15
+ ormlambda/common/errors/__init__.py,sha256=nc6SJs6v7MbXwcEgcSW7SSG_iBECfz_10YzWwqU1D-E,888
16
+ ormlambda/common/global_checker.py,sha256=R_m3_byStbnOj8qeVggHWBBR9VlkA_Lz5fm8M4OCzvY,890
17
+ ormlambda/common/interfaces/ICustomAlias.py,sha256=gEzjLFXT_JhkzGuBfWz36cqPrZ_B9999C3S61IicLoQ,159
18
+ ormlambda/common/interfaces/IDecompositionQuery.py,sha256=2fwcXONBnYpxL1YHPHaLxqQJ4NANGuTky69QNa74xd4,853
19
+ ormlambda/common/interfaces/IJoinSelector.py,sha256=-w-MJmwq65tpDLtigWSLgvAqeOl75DA-EyWIugNkfCs,490
20
+ ormlambda/common/interfaces/INonQueryCommand.py,sha256=7CjLW4sKqkR5zUIGvhRXOtzTs6vypJW1a9EJHlgCw2c,260
21
+ ormlambda/common/interfaces/IQueryCommand.py,sha256=hfzCosK4-n8RJIb2PYs8b0qU3TNmfYluZXBf47KxxKs,331
22
+ ormlambda/common/interfaces/__init__.py,sha256=np5wuAnBVAHDyD01-X3M9qPmzbjOzP6KNAj9BFazGd4,300
23
+ ormlambda/components/__init__.py,sha256=DfPVPLGLbQpbfBmXGKYcJRTELxzzdeNbZbuiMgZrPiA,168
24
+ ormlambda/components/delete/IDelete.py,sha256=06ZEdbKBxsHSwsGMBu0E1om4WJjojZAm-L3b95eQrcc,139
25
+ ormlambda/components/delete/__init__.py,sha256=X_at2L4QkxDVK1olXhFHqNemkB8Dxbb7BYqv0EJyu7M,102
26
+ ormlambda/components/delete/abstract_delete.py,sha256=ca-AO3nM9MMhy0hofNLjnCod92meiWzRT2vitj8N-l4,535
27
+ ormlambda/components/insert/IInsert.py,sha256=YIfMPlKu7UGgnVpZuhpr0Mtnefe-O85hqk8-GZrVK7w,139
28
+ ormlambda/components/insert/__init__.py,sha256=TGShCJZwejK3zZCRistBAKoDy2NNDRR_w1LXIbN66Dk,102
29
+ ormlambda/components/insert/abstract_insert.py,sha256=OmsfVMx8ifD2_ajRSXX8-EeKRTS7FTwbgSjdwASz_eg,695
30
+ ormlambda/components/select/ISelect.py,sha256=PcHvp8G1Zp_Gvn-_iZp-8SRBab7WVTxrtMr2FgQ_0sU,372
31
+ ormlambda/components/select/__init__.py,sha256=MAnVr3gsyXozsB9Q8jOl5KKCnOfQwxARuWpPS-h5Ooc,42
32
+ ormlambda/components/update/IUpdate.py,sha256=U-3Wx8lyCglhxf9gCXWO3MVgydG6gfRpzp00_MHC5cU,168
33
+ ormlambda/components/update/__init__.py,sha256=o1VjlfXgjftZgp64O10rzCGaDZCbdTZRRtjIlojTUWA,102
34
+ ormlambda/components/update/abstract_update.py,sha256=BXskuatPtWzYtB2xKN30SFTe4iVu_XApTNLjR0ZY5Ig,893
35
+ ormlambda/components/upsert/IUpsert.py,sha256=2m6Bcwa0X80IDLnf0QErqr01uYEydOnRta9_T1nxjK4,139
36
+ ormlambda/components/upsert/__init__.py,sha256=2hv7-McdU8Jv1ZJ4J3v94brN2H_fXvVDS8ZEA9CsfPA,102
37
+ ormlambda/components/upsert/abstract_upsert.py,sha256=a5_dJxTKI6GtxNTesxKtGFyy-AR6dXA6V2CAYiILn9o,695
38
+ ormlambda/databases/__init__.py,sha256=-m7uIigkbFNU5JHeOE8DeTA2bRVYEppw2XPASTSvW_o,136
39
+ ormlambda/databases/my_sql/__init__.py,sha256=2Ue97WtcpfB6-8SgUIHLOzk_iT44YUzG6baXCHmV9uA,212
40
+ ormlambda/databases/my_sql/caster/__init__.py,sha256=Df2sdZaAJ1Mi5Ego0sILMk5pF1NbK-nlV0hbpzd0PWE,47
41
+ ormlambda/databases/my_sql/caster/caster.py,sha256=D8hDwyZXOw5GRTQwONZyLaYe0sAimbDGb7DnDxUv_Ng,1181
42
+ ormlambda/databases/my_sql/caster/read.py,sha256=PBseYoNJtMgmr4sL5aD6uef0f-mm6LakAz-v-IcBs7w,1096
43
+ ormlambda/databases/my_sql/caster/types/__init__.py,sha256=lZ9YFqDjY6d6-Vy0tBMZfLI5EhyKXrb12Ys4eYiWjAg,396
44
+ ormlambda/databases/my_sql/caster/types/bytes.py,sha256=8rf2JEDFtwY5vsWZJ3r5Y8ruH76KwvRpLjjQOFdg5aA,896
45
+ ormlambda/databases/my_sql/caster/types/datetime.py,sha256=TXgHLJZ1v7LYqQnygK51K0WMHR96GVOOdtqd5HqXOx4,1053
46
+ ormlambda/databases/my_sql/caster/types/float.py,sha256=KCU6n6vH7c9NtRYbad91T-EEjKCDmr9iR_14Q6oswF4,890
47
+ ormlambda/databases/my_sql/caster/types/int.py,sha256=oqtZnqxVLysP2tTt5KXxWbpsYmv45gocU1MEBMaewBw,880
48
+ ormlambda/databases/my_sql/caster/types/iterable.py,sha256=kcaZcz7Mjip6CEG2oBlEQ7h9gAlo9PV5IosMm0WYOu4,893
49
+ ormlambda/databases/my_sql/caster/types/none.py,sha256=pdqcmcpHld-tM1-YjMJTrV7Aa_h2_sAprnRkaS-XIzc,784
50
+ ormlambda/databases/my_sql/caster/types/point.py,sha256=g5G691CsyQQtK6BGoKVpDzUtMRJNIKz_98xeHxqTGLE,1426
51
+ ormlambda/databases/my_sql/caster/types/string.py,sha256=NY03rRqLHAi_mxYWXDDIsPHtPiiw6pHAdSbn01yZuU4,887
52
+ ormlambda/databases/my_sql/caster/write.py,sha256=mfbtlAFamsnMbe1L4ARSAw2ch5qhz15jh5cSyAljcss,1322
53
+ ormlambda/databases/my_sql/clauses/ST_AsText.py,sha256=Fx-CgQ01aSkcuSlcdmLIWb7f3kd7r6kWs_BGu1HOVx8,1165
54
+ ormlambda/databases/my_sql/clauses/ST_Contains.py,sha256=K9cZwQaQQCgZTQdnAokln5lVSyV99CkeRnmOd2RIots,968
55
+ ormlambda/databases/my_sql/clauses/__init__.py,sha256=ZtIPgEoHXw5Dyv1U9aHnuKRhGQOPNhbtW1pNMUSfVvA,826
56
+ ormlambda/databases/my_sql/clauses/alias.py,sha256=NLISh_c8L7ZwN_13mhmVUxvop6kU-j2N09GmuDjLRXs,1147
57
+ ormlambda/databases/my_sql/clauses/count.py,sha256=rh7KNzpxkKEZpqmFV0oc8xHVgOHVGTGHrPGmCF-eLB4,1384
58
+ ormlambda/databases/my_sql/clauses/create_database.py,sha256=zpd8uosxKJsf9BULvAHSd1-fU5de8OI7WRqVa8oyiA4,1209
59
+ ormlambda/databases/my_sql/clauses/delete.py,sha256=Vm9lRKuX9x_m8faTlOs_A3v9zzoGGCnQ7CH_-QM6uK4,1900
60
+ ormlambda/databases/my_sql/clauses/drop_database.py,sha256=2GYhtWzHSWM7Yy3v_l2hiY4fFumG8DSCGGLgP0t3Rhk,437
61
+ ormlambda/databases/my_sql/clauses/drop_table.py,sha256=ltaJJFcNXChBF7fYGNCZK9QQ4iWfG72HFacL57f2k6A,569
62
+ ormlambda/databases/my_sql/clauses/group_by.py,sha256=u5cYkWslAGr1-NTLn-OdKZQAjfZdwwi7WH2TX2qhTec,900
63
+ ormlambda/databases/my_sql/clauses/insert.py,sha256=xR9IRiJeTIw-65MhnbK_uemMdvIEAaqFPg4IFBtC9Yk,3691
64
+ ormlambda/databases/my_sql/clauses/joins.py,sha256=PEq7_qxgjJK5R_m8WkqJWppEc-bQFIbAb88qn81uGOg,5170
65
+ ormlambda/databases/my_sql/clauses/limit.py,sha256=32Fii_WHjrX7K5B7H5uWlzYM6KBMFsE-Uz-70CEvTok,386
66
+ ormlambda/databases/my_sql/clauses/offset.py,sha256=PKieZvCYLSSza-Nhcam5DJEYv--jBU8RHwju3P_f9Kk,390
67
+ ormlambda/databases/my_sql/clauses/order.py,sha256=8sUKxWvkkOc5nn-r6GGL5MbFkCAD_St1CWMQkStSrLE,2147
68
+ ormlambda/databases/my_sql/clauses/select.py,sha256=O1dZWKG3_93-s_X_EjOF_alp_U82EzfDUKBMBcajxKY,1830
69
+ ormlambda/databases/my_sql/clauses/update.py,sha256=-3S_SwmSg_-qu_iDwhr1BY5ZtGGq0Og7eyO2YzdRFrU,2939
70
+ ormlambda/databases/my_sql/clauses/upsert.py,sha256=VJAwfvpIT3xXwm3AnifVqiswnYNleDTnbY0CgnQqC0s,1945
71
+ ormlambda/databases/my_sql/clauses/where.py,sha256=IR4BR4Rl13GiupCC3ilkUgqYu-LmISux7XZ6JIQGziw,1692
72
+ ormlambda/databases/my_sql/functions/__init__.py,sha256=hA8t3mUpV2p-pO4TVp5rjC5Yp7aIkWPsS8NpLi3DUh0,171
73
+ ormlambda/databases/my_sql/functions/concat.py,sha256=ih5An-1vxEVw0On0VLTuszVMku1c3eZmyUEdL4mO83o,1296
74
+ ormlambda/databases/my_sql/functions/max.py,sha256=01kkgougyP5m9_wdZB9_QvHKV86GnfZdotwsTSwAQfA,1493
75
+ ormlambda/databases/my_sql/functions/min.py,sha256=9g8twv0wUfpxrRK2socnfkJtmd_78pU6HDk_4AiV03c,1487
76
+ ormlambda/databases/my_sql/functions/sum.py,sha256=PUItqZ4ZbBcOfPzGbYDVvhVKV1RxLMuI63xNbSD8KrA,1487
77
+ ormlambda/databases/my_sql/join_context.py,sha256=CEKz0BPqkLBRoY9ciYAcLSon1jRNPq2-4HDw4ID8nkw,3192
78
+ ormlambda/databases/my_sql/repository/__init__.py,sha256=_T7m-UpgJlx7eYdjBw8jdSVFGnjFYAcbp45g4EM7YEk,54
79
+ ormlambda/databases/my_sql/repository/repository.py,sha256=AfTYGX96Sg9sNZNik69_e0r6YlP6fnuw92XPmk6wS-4,10246
80
+ ormlambda/databases/my_sql/statements.py,sha256=zAJ3432zMVp4GPjCOvaEn88eYxBqB71wHekTtdc-uak,15995
81
+ ormlambda/engine/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
+ ormlambda/engine/template.py,sha256=colmdl-IBSGc1eIqIYShsVkseQwF5_gwwc6Pt8ndN24,1350
83
+ ormlambda/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
84
+ ormlambda/model/base_model.py,sha256=S_PYs5ZO-LTgiJSyAmGUtXwFKLb9VnM2Rqlq4pdhppY,1021
85
+ ormlambda/repository/__init__.py,sha256=4KAhKn6vWV7bslewvGMNqbbbUnz1DLnH4yy-M5QNAQA,112
86
+ ormlambda/repository/base_repository.py,sha256=jyHkj33nP6kGEDAdqqXcADK9GH2MVY7MQVIZljZr2L0,448
87
+ ormlambda/repository/interfaces/IDatabaseConnection.py,sha256=pxczjx0b53yjjg5hvVDloMgUTFDahVC3HlJLQjo9_1w,283
88
+ ormlambda/repository/interfaces/IRepositoryBase.py,sha256=dxgMzALU_HtAiXwzUdNu4KeYR2PN_dqbepX4f_nA9NQ,1205
89
+ ormlambda/repository/interfaces/__init__.py,sha256=t8Mn0aRZm8uF4MGaqjEANTTADCdOwNF0THZ_qebyzwo,126
90
+ ormlambda/sql/__init__.py,sha256=0CWQzfxhTRWXozoRsg460o_ZwjW9w4uyL5jQUcD4eHg,121
91
+ ormlambda/sql/clause_info/__init__.py,sha256=ft8qh3pxXx3eAJfeBfSNwjzTjEAJob59XYLOnQQCJYI,205
92
+ ormlambda/sql/clause_info/clause_info.py,sha256=V4IQ6fuqf0Y-AS0qykQNcpOA2joib3FLuowNrMSBHNI,15644
93
+ ormlambda/sql/clause_info/clause_info_context.py,sha256=Y32p3x4mqcdNHbAowrKaN_ldnGn7zvaP1UdAkWWryhM,2852
94
+ ormlambda/sql/clause_info/interface/IAggregate.py,sha256=P-QPaTMAMHVR5M9-ClmL8wsj0uNGG5xpxjuAwWnzKxA,216
95
+ ormlambda/sql/clause_info/interface/__init__.py,sha256=7eEyHO7P_1DB63bP0ej5EjKkvb7IHwaGlSG58Hrv2X0,49
96
+ ormlambda/sql/column.py,sha256=pRrsFkUZlilvnHWDbKPvUhwyV-1bhYxlcYB-Fa8D7_4,5242
97
+ ormlambda/sql/comparer.py,sha256=XTi4QT2ICtssCPsF8yrMwLDswnu7lF3MO217hAAY0t8,5334
98
+ ormlambda/sql/dtypes.py,sha256=Ji4QOyKD0n9bKe7yXIIduy9uEX5BaXolQSIsx0NXYJY,7843
99
+ ormlambda/sql/foreign_key.py,sha256=lO_OiVTmMsFQpfp-102XZgPSsYBoVCO74i6YVdQ89yk,4773
100
+ ormlambda/sql/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
101
+ ormlambda/sql/table/__init__.py,sha256=nAHXi63eDJeGGCf4f0A7W6x4Rh3FJ2dpfzxPEN6r3bc,62
102
+ ormlambda/sql/table/fields.py,sha256=ovNR3bJ473aKW-2NhbKr0iJlVpgW06jurHLob2IyZU8,2116
103
+ ormlambda/sql/table/table_constructor.py,sha256=UQLxg2xZrNBH76MVQf-lp8de-TikZUNDIhWCNA9m7A4,8639
104
+ ormlambda/sql/types.py,sha256=z5FME0m9j7zSKlxS21cZxHRg0pyTfiJbq7VWZ6IT0kM,832
105
+ ormlambda/statements/__init__.py,sha256=mFER-VoLf5L2BjdQhWMw6rVQi8kpr-qZzi1ZSWRPIIU,99
106
+ ormlambda/statements/base_statement.py,sha256=WLjQrWw72NhBdNkP8uO1UP8hzfv-leyFjmMa4ofa-fk,5660
107
+ ormlambda/statements/interfaces/IStatements.py,sha256=nmpGRlsLqhx_uO9BYsUFiW48Qp8WhU2G-ePw4VtQiCA,10135
108
+ ormlambda/statements/interfaces/__init__.py,sha256=a3RyTNVA7DwWMqvVi7gFYP4MArdU-RUYixJcxfc79HY,76
109
+ ormlambda/statements/types.py,sha256=5HiOXjIm4aQzafB5Mq9b8OyBV2AyEH_P-kjQ8aQ8bIY,1743
110
+ ormlambda/utils/__init__.py,sha256=SEgDWkwbSrYRv0If92Ewq53DKnxxv5HqEAQbETd1C6Q,50
111
+ ormlambda/utils/module_tree/__init__.py,sha256=LNQtqkwO1ul49Th3aHAIiyt0Wt899GmXCc44Uz1eDyY,53
112
+ ormlambda/utils/module_tree/dfs_traversal.py,sha256=lSF03G63XtJFLp03ueAmsHMBvhUkjptDbK3IugXm8iU,1425
113
+ ormlambda/utils/module_tree/dynamic_module.py,sha256=SJWpOC5oqASGjCXYHW0JwzEpcZ_DkxKLyK4SpIsMbaA,8700
114
+ ormlambda-3.7.0.dist-info/LICENSE,sha256=xBprFw8GJLdHMOoUqDk0427EvjIcbEREvXXVFULuuXU,1080
115
+ ormlambda-3.7.0.dist-info/METADATA,sha256=mHVqTwLEX25rq7hhIuQaFkRJ50nUxN11749d8-BDSqc,9305
116
+ ormlambda-3.7.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
117
+ ormlambda-3.7.0.dist-info/RECORD,,
@@ -1,115 +0,0 @@
1
- from __future__ import annotations
2
- from typing import Any, Type, override, Iterable, Literal, TYPE_CHECKING, Optional
3
- from collections import defaultdict
4
- import abc
5
-
6
-
7
- from ormlambda.utils import Table
8
- from ormlambda.common.interfaces import IQuery, IRepositoryBase, IStatements_two_generic
9
- from ormlambda.common.interfaces.IAggregate import IAggregate
10
-
11
- if TYPE_CHECKING:
12
- from ormlambda.common.abstract_classes.decomposition_query import DecompositionQueryBase
13
- from ormlambda.common.abstract_classes.decomposition_query import ClauseInfo
14
-
15
-
16
- ORDER_QUERIES = Literal["select", "join", "where", "order", "with", "group by", "limit", "offset"]
17
-
18
-
19
- class AbstractSQLStatements[T: Table, *Ts, TRepo](IStatements_two_generic[T, *Ts, TRepo]):
20
- __slots__ = ("_model", "_repository", "_query_list")
21
- __order__: tuple[str, ...] = ("select", "join", "where", "order", "with", "group by", "limit", "offset")
22
-
23
- def __init__(self, model: tuple[T, *Ts], repository: IRepositoryBase[TRepo]) -> None:
24
- self.__valid_repository(repository)
25
-
26
- self._query: Optional[str] = None
27
- self._model: T = model[0] if isinstance(model, Iterable) else model
28
- self._models: tuple[T, *Ts] = self._model if isinstance(model, Iterable) else (model,)
29
- self._repository: IRepositoryBase[TRepo] = repository
30
- self._query_list: dict[ORDER_QUERIES, list[IQuery]] = defaultdict(list)
31
-
32
- if not issubclass(self._model, Table):
33
- # Deben heredar de Table ya que es la forma que tenemos para identificar si estamos pasando una instancia del tipo que corresponde o no cuando llamamos a insert o upsert.
34
- # Si no heredase de Table no sabriamos identificar el tipo de dato del que se trata porque al llamar a isinstance, obtendriamos el nombre de la clase que mapea a la tabla, Encargo, Edificio, Presupuesto y no podriamos crear una clase generica
35
- raise Exception(f"'{model}' class does not inherit from Table class")
36
-
37
- @staticmethod
38
- def __valid_repository(repository: Any) -> bool:
39
- if not isinstance(repository, IRepositoryBase):
40
- raise ValueError(f"'repository' attribute does not instance of '{IRepositoryBase.__name__}'")
41
- return True
42
-
43
- def __repr__(self):
44
- return f"<Model: {self.__class__.__name__}>"
45
-
46
- def _return_flavour[TValue](self, query, flavour: Type[TValue], select, **kwargs) -> tuple[TValue]:
47
- return self._repository.read_sql(query, flavour=flavour, model=self._model, select=select, **kwargs)
48
-
49
- def _return_model(self, select, query: str):
50
- response_sql = self._repository.read_sql(query, flavour=dict, model=self._model, select=select) # store all columns of the SQL query
51
-
52
- if isinstance(response_sql, Iterable):
53
- return ClusterQuery[T](select, response_sql).clean_response()
54
-
55
- return response_sql
56
-
57
- @abc.abstractmethod
58
- def _build(sef): ...
59
-
60
- @property
61
- def query(self) -> str:
62
- return self._query
63
-
64
- @property
65
- def model(self) -> Type[T]:
66
- return self._model
67
-
68
- @property
69
- def models(self) -> tuple[*Ts]:
70
- return self._models
71
-
72
- @property
73
- @override
74
- def repository(self) -> IRepositoryBase[TRepo]: ...
75
-
76
-
77
- class ClusterQuery[T]:
78
- def __init__(self, select: DecompositionQueryBase[T], response_sql: tuple[dict[str, Any]]) -> None:
79
- self._select: DecompositionQueryBase[T] = select
80
- self._response_sql: tuple[dict[str, Any]] = response_sql
81
-
82
- def clean_response(self) -> tuple[dict[Type[Table], tuple[Table]]]:
83
- tbl_dicc: dict[Type[Table], list[Table]] = self.__loop_foo()
84
-
85
- # it not depend of flavour attr
86
- for key, val in tbl_dicc.items():
87
- tbl_dicc[key] = tuple(val)
88
-
89
- return tuple(tbl_dicc.values())
90
-
91
- def __loop_foo(self) -> dict[Type[Table], list[Table]]:
92
- # We must ensure to get the valid attributes for each instance
93
- table_initialize = defaultdict(list)
94
-
95
- for table, clauses in self._select._clauses_group_by_tables.items():
96
- for dicc_cols in self._response_sql:
97
- valid_attr: dict[str, Any] = {}
98
- for clause in clauses:
99
- if clause.column is None or not hasattr(table, clause.column):
100
- agg_methods = self.__get_all_aggregate_method(clauses)
101
- raise ValueError(f"You cannot use aggregation method like '{agg_methods}' to return model objects. Try specifying 'flavour' attribute as 'dict'.")
102
- valid_attr[clause.column] = dicc_cols[clause.alias]
103
-
104
- # COMMENT: At this point we are going to instantiate Table class with specific attributes getting directly from database
105
- table_initialize[table].append(table(**valid_attr))
106
- return table_initialize
107
-
108
- def __get_all_aggregate_method(self, clauses: list[ClauseInfo]) -> str:
109
- res: set[str] = set()
110
-
111
- for clause in clauses:
112
- row = clause._row_column
113
- if isinstance(row, IAggregate):
114
- res.add(row.__class__.__name__)
115
- return ", ".join(res)
@@ -1,10 +0,0 @@
1
- from __future__ import annotations
2
- import typing as tp
3
-
4
- if tp.TYPE_CHECKING:
5
- from ormlambda import Table
6
- from .IQueryCommand import IQuery
7
- from .IDecompositionQuery import IDecompositionQuery
8
-
9
-
10
- class IAggregate[T: tp.Type[Table]](IDecompositionQuery[T], IQuery): ...