jararaca 0.2.30__py3-none-any.whl → 0.2.31__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.
Potentially problematic release.
This version of jararaca might be problematic. Click here for more details.
- jararaca/persistence/sort_filter.py +42 -4
- jararaca/persistence/utilities.py +20 -1
- {jararaca-0.2.30.dist-info → jararaca-0.2.31.dist-info}/METADATA +1 -1
- {jararaca-0.2.30.dist-info → jararaca-0.2.31.dist-info}/RECORD +8 -8
- pyproject.toml +1 -1
- {jararaca-0.2.30.dist-info → jararaca-0.2.31.dist-info}/LICENSE +0 -0
- {jararaca-0.2.30.dist-info → jararaca-0.2.31.dist-info}/WHEEL +0 -0
- {jararaca-0.2.30.dist-info → jararaca-0.2.31.dist-info}/entry_points.txt +0 -0
|
@@ -10,7 +10,7 @@ from sqlalchemy.orm.attributes import InstrumentedAttribute
|
|
|
10
10
|
from jararaca import BaseEntity
|
|
11
11
|
|
|
12
12
|
FILTER_SORT_ENTITY_ATTR_MAP = dict[
|
|
13
|
-
str, InstrumentedAttribute[str | int | datetime | date | UUID]
|
|
13
|
+
str, InstrumentedAttribute[str | int | datetime | date | UUID | None]
|
|
14
14
|
]
|
|
15
15
|
|
|
16
16
|
|
|
@@ -54,14 +54,12 @@ class FilterModel(BaseModel):
|
|
|
54
54
|
INHERITS_BASE_ENTITY = TypeVar("INHERITS_BASE_ENTITY", bound=BaseEntity)
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
class
|
|
57
|
+
class FilterRuleApplier:
|
|
58
58
|
def __init__(
|
|
59
59
|
self,
|
|
60
60
|
allowed_filters: FILTER_SORT_ENTITY_ATTR_MAP,
|
|
61
|
-
allowed_sorts: FILTER_SORT_ENTITY_ATTR_MAP,
|
|
62
61
|
):
|
|
63
62
|
self.allowed_filters = allowed_filters
|
|
64
|
-
self.allowed_sorts = allowed_sorts
|
|
65
63
|
|
|
66
64
|
def create_query_for_filter(
|
|
67
65
|
self, query: Select[Tuple[INHERITS_BASE_ENTITY]], filter: FilterModel
|
|
@@ -168,6 +166,14 @@ class SortFilterRunner:
|
|
|
168
166
|
) -> Select[Tuple[INHERITS_BASE_ENTITY]]:
|
|
169
167
|
return reduce(lambda q, f: self.create_query_for_filter(q, f), filters, query)
|
|
170
168
|
|
|
169
|
+
|
|
170
|
+
class SortRuleApplier:
|
|
171
|
+
def __init__(
|
|
172
|
+
self,
|
|
173
|
+
allowed_sorts: FILTER_SORT_ENTITY_ATTR_MAP,
|
|
174
|
+
):
|
|
175
|
+
self.allowed_sorts = allowed_sorts
|
|
176
|
+
|
|
171
177
|
def create_query_for_sorting(
|
|
172
178
|
self, query: Select[Tuple[INHERITS_BASE_ENTITY]], sort: SortModel
|
|
173
179
|
) -> Select[Tuple[INHERITS_BASE_ENTITY]]:
|
|
@@ -182,6 +188,38 @@ class SortFilterRunner:
|
|
|
182
188
|
return reduce(lambda q, s: self.create_query_for_sorting(q, s), sorts, query)
|
|
183
189
|
|
|
184
190
|
|
|
191
|
+
class SortFilterRunner:
|
|
192
|
+
def __init__(
|
|
193
|
+
self,
|
|
194
|
+
allowed_filters: FILTER_SORT_ENTITY_ATTR_MAP,
|
|
195
|
+
allowed_sorts: FILTER_SORT_ENTITY_ATTR_MAP,
|
|
196
|
+
):
|
|
197
|
+
self.allowed_filters = allowed_filters
|
|
198
|
+
self.allowed_sorts = allowed_sorts
|
|
199
|
+
self.filter_rule_applier = FilterRuleApplier(allowed_filters)
|
|
200
|
+
self.sort_rule_applier = SortRuleApplier(allowed_sorts)
|
|
201
|
+
|
|
202
|
+
def create_query_for_filter(
|
|
203
|
+
self, query: Select[Tuple[INHERITS_BASE_ENTITY]], filter: FilterModel
|
|
204
|
+
) -> Select[Tuple[INHERITS_BASE_ENTITY]]:
|
|
205
|
+
return self.filter_rule_applier.create_query_for_filter(query, filter)
|
|
206
|
+
|
|
207
|
+
def create_query_for_filter_list(
|
|
208
|
+
self, query: Select[Tuple[INHERITS_BASE_ENTITY]], filters: list[FilterModel]
|
|
209
|
+
) -> Select[Tuple[INHERITS_BASE_ENTITY]]:
|
|
210
|
+
return self.filter_rule_applier.create_query_for_filter_list(query, filters)
|
|
211
|
+
|
|
212
|
+
def create_query_for_sorting(
|
|
213
|
+
self, query: Select[Tuple[INHERITS_BASE_ENTITY]], sort: SortModel
|
|
214
|
+
) -> Select[Tuple[INHERITS_BASE_ENTITY]]:
|
|
215
|
+
return self.sort_rule_applier.create_query_for_sorting(query, sort)
|
|
216
|
+
|
|
217
|
+
def create_query_for_sorting_list(
|
|
218
|
+
self, query: Select[Tuple[INHERITS_BASE_ENTITY]], sorts: list[SortModel]
|
|
219
|
+
) -> Select[Tuple[INHERITS_BASE_ENTITY]]:
|
|
220
|
+
return self.sort_rule_applier.create_query_for_sorting_list(query, sorts)
|
|
221
|
+
|
|
222
|
+
|
|
185
223
|
__all__ = [
|
|
186
224
|
"SortFilterRunner",
|
|
187
225
|
"FilterModel",
|
|
@@ -29,7 +29,12 @@ from jararaca.persistence.base import (
|
|
|
29
29
|
BaseEntity,
|
|
30
30
|
recursive_get_dict,
|
|
31
31
|
)
|
|
32
|
-
from jararaca.persistence.sort_filter import
|
|
32
|
+
from jararaca.persistence.sort_filter import (
|
|
33
|
+
FilterModel,
|
|
34
|
+
FilterRuleApplier,
|
|
35
|
+
SortModel,
|
|
36
|
+
SortRuleApplier,
|
|
37
|
+
)
|
|
33
38
|
|
|
34
39
|
logger = logging.getLogger(__name__)
|
|
35
40
|
|
|
@@ -257,11 +262,15 @@ class QueryOperations(Generic[QUERY_FILTER_T, QUERY_ENTITY_T]):
|
|
|
257
262
|
session_provider: Callable[[], AsyncSession],
|
|
258
263
|
filters_functions: list[QueryInjector],
|
|
259
264
|
unique: bool = False,
|
|
265
|
+
sort_rule_applier: SortRuleApplier | None = None,
|
|
266
|
+
filter_rule_applier: FilterRuleApplier | None = None,
|
|
260
267
|
) -> None:
|
|
261
268
|
self.entity_type: type[QUERY_ENTITY_T] = entity_type
|
|
262
269
|
self.session_provider = session_provider
|
|
263
270
|
self.filters_functions = filters_functions
|
|
264
271
|
self.unique = unique
|
|
272
|
+
self.sort_rule_applier = sort_rule_applier
|
|
273
|
+
self.filter_rule_applier = filter_rule_applier
|
|
265
274
|
|
|
266
275
|
@property
|
|
267
276
|
def session(self) -> AsyncSession:
|
|
@@ -281,6 +290,16 @@ class QueryOperations(Generic[QUERY_FILTER_T, QUERY_ENTITY_T]):
|
|
|
281
290
|
select(self.entity_type),
|
|
282
291
|
)
|
|
283
292
|
|
|
293
|
+
if self.sort_rule_applier:
|
|
294
|
+
query = self.sort_rule_applier.create_query_for_sorting_list(
|
|
295
|
+
query, filter.sort_models
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
if self.filter_rule_applier:
|
|
299
|
+
query = self.filter_rule_applier.create_query_for_filter_list(
|
|
300
|
+
query, filter.filter_models
|
|
301
|
+
)
|
|
302
|
+
|
|
284
303
|
unpaginated_total = (
|
|
285
304
|
await self.session.execute(
|
|
286
305
|
select(func.count()).select_from(query.subquery())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
2
2
|
README.md,sha256=mte30I-ZEJJp-Oax-OganNgl6G9GaCZPL6JVFAvZGz4,7034
|
|
3
|
-
pyproject.toml,sha256=
|
|
3
|
+
pyproject.toml,sha256=B4Nlc2p6KK52GQ0X5NjBeU1WN9gBpXAr-1yR0b7V-5M,1837
|
|
4
4
|
jararaca/__init__.py,sha256=h1lYQMmB8TATPG0GXjIzLZWHbWFhvkAFu-yBjm2W18g,13875
|
|
5
5
|
jararaca/__main__.py,sha256=-O3vsB5lHdqNFjUtoELDF81IYFtR-DSiiFMzRaiSsv4,67
|
|
6
6
|
jararaca/cli.py,sha256=fh7lp7rf5xbV5VaoSYWWehktel6BPcOXMjW7cw4wKms,5693
|
|
@@ -28,8 +28,8 @@ jararaca/persistence/exports.py,sha256=Ghx4yoFaB4QVTb9WxrFYgmcSATXMNvrOvT8ybPNKX
|
|
|
28
28
|
jararaca/persistence/interceptors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
29
|
jararaca/persistence/interceptors/aiosqa_interceptor.py,sha256=H6ZjOdosYGCZUzKjugiXQwJkAbnsL4HnkZLOEQhULEc,1986
|
|
30
30
|
jararaca/persistence/session.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
31
|
-
jararaca/persistence/sort_filter.py,sha256=
|
|
32
|
-
jararaca/persistence/utilities.py,sha256=
|
|
31
|
+
jararaca/persistence/sort_filter.py,sha256=fq-YfBJnGSqRK4uaUc9E_aIQiO0Pxo5EooZL5PoUgpM,8312
|
|
32
|
+
jararaca/persistence/utilities.py,sha256=v9ckhzti3GKWQrng2I03EO-dxGRGp-sLoVnVNf_UFU4,12478
|
|
33
33
|
jararaca/presentation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
34
|
jararaca/presentation/decorators.py,sha256=eL2YCgMSr19m4YCri5PQU46NRxf0QxsqDnz6MqKu0YQ,8389
|
|
35
35
|
jararaca/presentation/hooks.py,sha256=WBbU5DG3-MAm2Ro2YraQyYG_HENfizYfyShL2ktHi6k,1980
|
|
@@ -58,8 +58,8 @@ jararaca/tools/app_config/decorators.py,sha256=-ckkMZ1dswOmECdo1rFrZ15UAku--txaN
|
|
|
58
58
|
jararaca/tools/app_config/interceptor.py,sha256=nfFZiS80hrbnL7-XEYrwmp2rwaVYBqxvqu3Y-6o_ov4,2575
|
|
59
59
|
jararaca/tools/metadata.py,sha256=7nlCDYgItNybentPSSCc2MLqN7IpBd0VyQzfjfQycVI,1402
|
|
60
60
|
jararaca/tools/typescript/interface_parser.py,sha256=_dPBRKs_67eiQ8cPWp8q1uGbIPxZ30dypfoqhbBAL_Y,28790
|
|
61
|
-
jararaca-0.2.
|
|
62
|
-
jararaca-0.2.
|
|
63
|
-
jararaca-0.2.
|
|
64
|
-
jararaca-0.2.
|
|
65
|
-
jararaca-0.2.
|
|
61
|
+
jararaca-0.2.31.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
62
|
+
jararaca-0.2.31.dist-info/METADATA,sha256=U4wm5ZcJFUbus2tiJHd2rV9GFG0wJc8N_n7qQADy4P8,8552
|
|
63
|
+
jararaca-0.2.31.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
64
|
+
jararaca-0.2.31.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
|
|
65
|
+
jararaca-0.2.31.dist-info/RECORD,,
|
pyproject.toml
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|