python-general-be-lib 0.5.3__py3-none-any.whl → 0.5.4__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.
- general/interface/repository/crud_repository.py +13 -4
- general/interface/repository/handler/statement_manager.py +5 -4
- {python_general_be_lib-0.5.3.dist-info → python_general_be_lib-0.5.4.dist-info}/METADATA +1 -1
- {python_general_be_lib-0.5.3.dist-info → python_general_be_lib-0.5.4.dist-info}/RECORD +7 -7
- {python_general_be_lib-0.5.3.dist-info → python_general_be_lib-0.5.4.dist-info}/WHEEL +0 -0
- {python_general_be_lib-0.5.3.dist-info → python_general_be_lib-0.5.4.dist-info}/licenses/LICENSE +0 -0
- {python_general_be_lib-0.5.3.dist-info → python_general_be_lib-0.5.4.dist-info}/top_level.txt +0 -0
|
@@ -217,12 +217,13 @@ class CrudRepository[Entity: Base | Type[Base]]:
|
|
|
217
217
|
else:
|
|
218
218
|
pass
|
|
219
219
|
|
|
220
|
-
def find(self, session: Session = None, where: dict[str, Any] = None, columns: list[str] = None, exclude_columns: list[str] = None, limit: int = 0, parsing_model: Type[BaseModel] = None,
|
|
220
|
+
def find(self, session: Session = None, where: dict[str, Any] = None, columns: list[str] = None, exclude_columns: list[str] = None, limit: int = 0, parsing_model: Type[BaseModel] = None, order_by: str = None,
|
|
221
|
+
asc: bool = None, **kwhere) -> list[Entity]:
|
|
221
222
|
"""Cerca i record che corrispondono ai criteri specificati.
|
|
222
223
|
|
|
223
224
|
I filtri possono essere passati come dizionario ``where`` o come
|
|
224
225
|
keyword arguments. Supporta caricamento parziale delle colonne,
|
|
225
|
-
limit e modelli di parsing alternativi.
|
|
226
|
+
limit, ordinamento e modelli di parsing alternativi.
|
|
226
227
|
|
|
227
228
|
Args:
|
|
228
229
|
session (Session, optional): Sessione esterna. Se ``None``, ne viene
|
|
@@ -234,6 +235,10 @@ class CrudRepository[Entity: Base | Type[Base]]:
|
|
|
234
235
|
limit (int): Numero massimo di risultati. 0 = nessun limite. Default: 0.
|
|
235
236
|
parsing_model (Type[BaseModel], optional): Modello Pydantic alternativo
|
|
236
237
|
per la serializzazione del risultato.
|
|
238
|
+
order_by (str, optional): Nome della colonna per l'ordinamento dei risultati.
|
|
239
|
+
Se ``None``, non viene applicato nessun ordinamento.
|
|
240
|
+
asc (bool, optional): Direzione dell'ordinamento. ``True`` per ASC,
|
|
241
|
+
``False`` per DESC. Se ``None``, l'ordinamento di default è DESC.
|
|
237
242
|
**kwhere: Filtri aggiuntivi come keyword arguments.
|
|
238
243
|
|
|
239
244
|
Returns:
|
|
@@ -243,17 +248,21 @@ class CrudRepository[Entity: Base | Type[Base]]:
|
|
|
243
248
|
Example:
|
|
244
249
|
>>> repo.find(active=True, limit=10)
|
|
245
250
|
>>> repo.find(where={"role": ["admin", "editor"]})
|
|
251
|
+
>>> repo.find(active=True, order_by="name", asc=True)
|
|
246
252
|
"""
|
|
253
|
+
|
|
247
254
|
keep_open = False if session is None else True
|
|
248
255
|
session = self.open_session if session is None else session
|
|
249
|
-
entities = self._find(session=session, where=where, columns=columns, exclude_columns=exclude_columns, limit=limit, **kwhere)
|
|
256
|
+
entities = self._find(session=session, where=where, columns=columns, exclude_columns=exclude_columns, limit=limit, order_by=order_by, asc=asc, **kwhere)
|
|
250
257
|
return self._return(session=session, entities=entities, keep_open=keep_open, commit=False, parsing_model=parsing_model)
|
|
251
258
|
|
|
252
|
-
def _find(self, session: Session, where: dict[str, Any] = None, columns: list[str] = None, exclude_columns: list[str] = None, limit: int = 0,
|
|
259
|
+
def _find(self, session: Session, where: dict[str, Any] = None, columns: list[str] = None, exclude_columns: list[str] = None, limit: int = 0, order_by: str = None,
|
|
260
|
+
asc: bool = None, **kwhere):
|
|
253
261
|
if where is None:
|
|
254
262
|
where = kwhere if kwhere else {}
|
|
255
263
|
stmt = self._select(entity=self.entity, columns=columns, exclude_columns=exclude_columns)
|
|
256
264
|
stmt = self.stmt_manager.prepare_statement(stmt=stmt, **where)
|
|
265
|
+
stmt = self.stmt_manager.order_by_condition(stmt=stmt, order_by=order_by, asc=asc)
|
|
257
266
|
stmt = self.stmt_manager.limit_offset_condition(stmt=stmt, limit=limit)
|
|
258
267
|
return self.execute(session, stmt)
|
|
259
268
|
|
|
@@ -74,10 +74,11 @@ class StatementManager:
|
|
|
74
74
|
Raises:
|
|
75
75
|
HasNoAttributeException: Se la colonna ``order_by`` non esiste sull'entità.
|
|
76
76
|
"""
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
if order_by:
|
|
78
|
+
try:
|
|
79
|
+
stmt = stmt.order_by(self._base_handler.columns[order_by].asc()) if asc else stmt.order_by(self._base_handler.columns[order_by].desc())
|
|
80
|
+
except KeyError:
|
|
81
|
+
raise HasNoAttributeException(order_by)
|
|
81
82
|
return stmt
|
|
82
83
|
|
|
83
84
|
def limit_offset_condition(self, stmt: Select, limit: int, page: int = None):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-general-be-lib
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.4
|
|
4
4
|
Summary: General purpose backend library — SQLAlchemy CRUD/Geometry repositories, FastAPI exceptions, Pydantic base models, logger utilities.
|
|
5
5
|
Author-email: Andrea Di Placido <a.diplacido@arpes.it>, "Arpes S.r.l." <it.admin@arpes.it>
|
|
6
6
|
License: MIT
|
|
@@ -13,7 +13,7 @@ general/interface/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
|
|
|
13
13
|
general/interface/metadata/crud_metadata.py,sha256=z1fTh77K7fkhDgNus5Xrv4EYerbdlPVl4F1NLbSxqcM,8478
|
|
14
14
|
general/interface/metadata/geom_metadata.py,sha256=CZPzlqos5XuDWn_FeKLxxYqOuGx1Bg9C0xH5-ZR0vXw,5326
|
|
15
15
|
general/interface/repository/__init__.py,sha256=EcRukwf61Ua-9-JfM_ingVv1wXNRV8HBrrWwjj8m23w,136
|
|
16
|
-
general/interface/repository/crud_repository.py,sha256=
|
|
16
|
+
general/interface/repository/crud_repository.py,sha256=wFO_OhyDDh_KxzQbO0QjACLacF83SMdbsOD2MJa6510,29210
|
|
17
17
|
general/interface/repository/geometry_repository.py,sha256=bJVPhsr-fGhVTywdHwx9Qt_inWPHk5wqq9EFWFLfuGU,11181
|
|
18
18
|
general/interface/repository/many_to_many_repository.py,sha256=iEhWyD8nPZSAPL8Z2wXrK-aRBnoh3evaSN-voaf0EP0,8662
|
|
19
19
|
general/interface/repository/view_repository.py,sha256=Sm591FUP0iBYlI-ULNWszD5fOvTGwXX0iYoeDbUqo34,5397
|
|
@@ -23,9 +23,9 @@ general/interface/repository/handler/ilike_handler.py,sha256=_HHTvj6Tm1L-WvUy1S9
|
|
|
23
23
|
general/interface/repository/handler/interval_handler.py,sha256=XxMQr6UuWnoCtbOOO7l80_Yja_aPKYtHhDfhFCRMaKg,4135
|
|
24
24
|
general/interface/repository/handler/json_handler.py,sha256=7bS59seB-It5KHsWXTbHGsEvbQZ6lYyvX-d29BcRLVE,2956
|
|
25
25
|
general/interface/repository/handler/json_ilike_handler.py,sha256=yDuKER3yqtnHpVWndF8PVEaqDThcq1EhZzLaqxbQ0bU,4491
|
|
26
|
-
general/interface/repository/handler/statement_manager.py,sha256=
|
|
27
|
-
python_general_be_lib-0.5.
|
|
28
|
-
python_general_be_lib-0.5.
|
|
29
|
-
python_general_be_lib-0.5.
|
|
30
|
-
python_general_be_lib-0.5.
|
|
31
|
-
python_general_be_lib-0.5.
|
|
26
|
+
general/interface/repository/handler/statement_manager.py,sha256=sGDMU4fPkF0_9-SbDmAw8Vpel1Z7eImBs8fHO-5Lr_0,4429
|
|
27
|
+
python_general_be_lib-0.5.4.dist-info/licenses/LICENSE,sha256=iUaO1XZyB9P3Tmog0OILuTisP6vXGe3QKz-4yRTxOFk,1069
|
|
28
|
+
python_general_be_lib-0.5.4.dist-info/METADATA,sha256=oOe-yd6hkXQ1wumjhGiEO90OI7bRcZRJw0UlamThdaU,1384
|
|
29
|
+
python_general_be_lib-0.5.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
30
|
+
python_general_be_lib-0.5.4.dist-info/top_level.txt,sha256=tTZePW8_CNUqSgKFd2SEH72ZbnhS0OYjRsgcv0ikSFY,8
|
|
31
|
+
python_general_be_lib-0.5.4.dist-info/RECORD,,
|
|
File without changes
|
{python_general_be_lib-0.5.3.dist-info → python_general_be_lib-0.5.4.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{python_general_be_lib-0.5.3.dist-info → python_general_be_lib-0.5.4.dist-info}/top_level.txt
RENAMED
|
File without changes
|