nlbone 0.6.11__py3-none-any.whl → 0.6.12__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.
@@ -28,6 +28,50 @@ class _InvalidEnum(Exception):
28
28
  pass
29
29
 
30
30
 
31
+ from sqlalchemy.orm import aliased
32
+ from sqlalchemy.inspection import inspect
33
+ from sqlalchemy.orm.attributes import InstrumentedAttribute
34
+ from sqlalchemy.orm.relationships import RelationshipProperty
35
+
36
+
37
+ def _resolve_column_and_joins(entity, query, field_path: str, join_cache: dict[str, Any]):
38
+ parts = [p for p in field_path.split(".") if p]
39
+ if not parts:
40
+ return None, query
41
+
42
+ current_cls_or_alias = entity
43
+ current_path_key_parts: list[str] = []
44
+
45
+ for i, part in enumerate(parts):
46
+ current_path_key_parts.append(part)
47
+ path_key = ".".join(current_path_key_parts)
48
+
49
+ if not hasattr(current_cls_or_alias, part):
50
+ return None, query
51
+
52
+ attr = getattr(current_cls_or_alias, part)
53
+
54
+ prop = getattr(attr, "property", None)
55
+ if isinstance(prop, RelationshipProperty):
56
+ alias = join_cache.get(path_key)
57
+ if alias is None:
58
+ alias = aliased(prop.mapper.class_)
59
+ query = query.outerjoin(alias, attr)
60
+ join_cache[path_key] = alias
61
+ current_cls_or_alias = alias
62
+ continue
63
+
64
+ if isinstance(attr, InstrumentedAttribute):
65
+ if i == len(parts) - 1:
66
+ return attr, query
67
+ else:
68
+ return None, query
69
+
70
+ return None, query
71
+
72
+ return None, query
73
+
74
+
31
75
  def _apply_order(pagination: PaginateRequest, entity, query):
32
76
  order_clauses = []
33
77
 
@@ -112,6 +156,7 @@ def _apply_filters(pagination, entity, query):
112
156
  return query
113
157
 
114
158
  predicates = []
159
+ join_cache: dict[str, Any] = {}
115
160
 
116
161
  if getattr(pagination, "filters", None):
117
162
  for raw_field, value in pagination.filters.items():
@@ -120,10 +165,10 @@ def _apply_filters(pagination, entity, query):
120
165
 
121
166
  field, op_hint = _parse_field_and_op(raw_field)
122
167
 
123
- if not hasattr(entity, field):
168
+ col, query2 = _resolve_column_and_joins(entity, query, field, join_cache)
169
+ if col is None:
124
170
  continue
125
-
126
- col = getattr(entity, field)
171
+ query = query2
127
172
  coltype = getattr(col, "type", None)
128
173
 
129
174
  def coerce(v):
@@ -259,13 +304,13 @@ def _serialize_item(item: Any, output_cls: OutputType) -> Any:
259
304
 
260
305
 
261
306
  def get_paginated_response(
262
- pagination,
263
- entity,
264
- session: Session,
265
- *,
266
- with_count: bool = True,
267
- output_cls: Optional[Type] = None,
268
- eager_options: Optional[Sequence[LoaderOption]] = None,
307
+ pagination,
308
+ entity,
309
+ session: Session,
310
+ *,
311
+ with_count: bool = True,
312
+ output_cls: Optional[Type] = None,
313
+ eager_options: Optional[Sequence[LoaderOption]] = None,
269
314
  ) -> dict:
270
315
  query = session.query(entity)
271
316
  if eager_options:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nlbone
3
- Version: 0.6.11
3
+ Version: 0.6.12
4
4
  Summary: Backbone package for interfaces and infrastructure in Python projects
5
5
  Author-email: Amir Hosein Kahkbazzadeh <a.khakbazzadeh@gmail.com>
6
6
  License: MIT
@@ -15,7 +15,7 @@ nlbone/adapters/db/postgres/__init__.py,sha256=6JYJH0xZs3aR-zuyMpRhsdzFugmqz8npr
15
15
  nlbone/adapters/db/postgres/audit.py,sha256=8f5XOuW7_ybJyy_STam1FNzqmZAAVAu7tmMRUkCGJOM,4594
16
16
  nlbone/adapters/db/postgres/base.py,sha256=kha9xmklzhuQAK8QEkNBn-mAHq8dUKbOM-3abaBpWmQ,71
17
17
  nlbone/adapters/db/postgres/engine.py,sha256=UCegauVB1gvo42ThytYnn5VIcQBwR-5xhcXYFApRFNk,3448
18
- nlbone/adapters/db/postgres/query_builder.py,sha256=HVGtgWm0AtbjAtW3E3K9KVnJixcZWXMuk5uNqzZQJnQ,9381
18
+ nlbone/adapters/db/postgres/query_builder.py,sha256=SNNkmoMuzcuOwxZlTlplAGqJ0mDQevixLOruqHPa8zM,10855
19
19
  nlbone/adapters/db/postgres/repository.py,sha256=J_DBE73JhHPYCk90c5-O7lQtZbxDgqjjN9OcWy4Omvs,1660
20
20
  nlbone/adapters/db/postgres/schema.py,sha256=NlE7Rr8uXypsw4oWkdZhZwcIBHQEPIpoHLxcUo98i6s,1039
21
21
  nlbone/adapters/db/postgres/uow.py,sha256=nRxNpY-WoWHpym-XeZ8VHm0MYvtB9wuopOeNdV_ebk8,2088
@@ -84,8 +84,8 @@ nlbone/utils/context.py,sha256=MmclJ24BG2uvSTg1IK7J-Da9BhVFDQ5ag4Ggs2FF1_w,1600
84
84
  nlbone/utils/http.py,sha256=UXUoXgQdTRNT08ho8zl-C5ekfDsD8uf-JiMQ323ooqw,872
85
85
  nlbone/utils/redactor.py,sha256=-V4HrHmHwPi3Kez587Ek1uJlgK35qGSrwBOvcbw8Jas,1279
86
86
  nlbone/utils/time.py,sha256=DjjyQ9GLsfXoT6NK8RDW2rOlJg3e6sF04Jw6PBUrSvg,1268
87
- nlbone-0.6.11.dist-info/METADATA,sha256=_AtHFMQwxHiwO8I-RV-hNDm3ToQMmbuidYTkvvQPnmc,2228
88
- nlbone-0.6.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
89
- nlbone-0.6.11.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
90
- nlbone-0.6.11.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
91
- nlbone-0.6.11.dist-info/RECORD,,
87
+ nlbone-0.6.12.dist-info/METADATA,sha256=l0a2XnCXdUv6VvOv_p880moTJFSwVLzLCC6L8NtapMg,2228
88
+ nlbone-0.6.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
89
+ nlbone-0.6.12.dist-info/entry_points.txt,sha256=CpIL45t5nbhl1dGQPhfIIDfqqak3teK0SxPGBBr7YCk,59
90
+ nlbone-0.6.12.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
91
+ nlbone-0.6.12.dist-info/RECORD,,