querymodelling 0.0.2a0__tar.gz → 0.0.4__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.
- {querymodelling-0.0.2a0/querymodelling.egg-info → querymodelling-0.0.4}/PKG-INFO +1 -1
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/pyproject.toml +1 -1
- querymodelling-0.0.4/querymodelling/__helper__.py +8 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling/__version__.py +1 -1
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling/sql.py +37 -7
- {querymodelling-0.0.2a0 → querymodelling-0.0.4/querymodelling.egg-info}/PKG-INFO +1 -1
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling.egg-info/SOURCES.txt +1 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/AUTHORS.rst +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/LICENSE +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/README.md +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling/__init__.py +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling/base.py +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling/fields.py +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling/model.py +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling/pydantic.py +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling.egg-info/dependency_links.txt +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling.egg-info/requires.txt +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling.egg-info/top_level.txt +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/setup.cfg +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/setup.py +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/tests/__init__.py +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/tests/__main__.py +0 -0
- {querymodelling-0.0.2a0 → querymodelling-0.0.4}/tests/basic_test.py +0 -0
|
@@ -4,6 +4,7 @@ from sqlalchemy.orm.attributes import InstrumentedAttribute
|
|
|
4
4
|
from typing import TypeVar, Sequence, Type, Callable, ParamSpec
|
|
5
5
|
from pydantic import AliasChoices
|
|
6
6
|
|
|
7
|
+
from .__helper__ import is_enum
|
|
7
8
|
from .base import get_functions, DefaultSort
|
|
8
9
|
from .fields import QueryField, SortField
|
|
9
10
|
from .model import PageQuery
|
|
@@ -21,7 +22,7 @@ def sortable_by(field):
|
|
|
21
22
|
return field.asc()
|
|
22
23
|
return wrapper
|
|
23
24
|
|
|
24
|
-
def
|
|
25
|
+
def retrieve_paged_entries(
|
|
25
26
|
query: Q,
|
|
26
27
|
session: Session,
|
|
27
28
|
t: Type[T],
|
|
@@ -47,6 +48,20 @@ def retrieve_entries(
|
|
|
47
48
|
|
|
48
49
|
return total_elements, session.exec(statement).all()
|
|
49
50
|
|
|
51
|
+
def retrieve_entries(
|
|
52
|
+
query: Q,
|
|
53
|
+
session: Session,
|
|
54
|
+
t: Type[T]
|
|
55
|
+
) -> tuple[int, Sequence[T]]:
|
|
56
|
+
search_clause = get_functions(query, "query")
|
|
57
|
+
order_clause = get_functions(query, "sort")
|
|
58
|
+
statement = select(t)
|
|
59
|
+
if search_clause:
|
|
60
|
+
statement = statement.where(*search_clause)
|
|
61
|
+
if order_clause:
|
|
62
|
+
statement = statement.order_by(*order_clause)
|
|
63
|
+
return session.exec(statement).all()
|
|
64
|
+
|
|
50
65
|
def create_query_fields(
|
|
51
66
|
base_field: any,
|
|
52
67
|
field_name: str,
|
|
@@ -71,7 +86,6 @@ def create_query_fields(
|
|
|
71
86
|
validation_alias=validation_alias,
|
|
72
87
|
default=None,
|
|
73
88
|
json_schema_extra=json_schema_extra | {
|
|
74
|
-
"query.backend": "sql",
|
|
75
89
|
"query.operator": operator
|
|
76
90
|
}
|
|
77
91
|
),
|
|
@@ -98,9 +112,14 @@ def create_callback(
|
|
|
98
112
|
json_schema_extra[property_name] = field_info[
|
|
99
113
|
property_name]
|
|
100
114
|
|
|
115
|
+
json_schema_extra = json_schema_extra | {
|
|
116
|
+
"query.backend": "sql"
|
|
117
|
+
}
|
|
118
|
+
|
|
101
119
|
if annotation == str:
|
|
102
120
|
operator_mapping = {
|
|
103
121
|
None: lambda value: field == value,
|
|
122
|
+
"not": lambda value: field != value,
|
|
104
123
|
"startswith": lambda value: field.like(f"{value}%"),
|
|
105
124
|
"endswith": lambda value: field.like(f"%{value}"),
|
|
106
125
|
"contains": lambda value: field.like(f"%{value}%")
|
|
@@ -116,7 +135,20 @@ def create_callback(
|
|
|
116
135
|
operator_mapping = {
|
|
117
136
|
None: lambda value: field == value,
|
|
118
137
|
"from": lambda value: field >= value,
|
|
119
|
-
"to": lambda value: field <= value
|
|
138
|
+
"to": lambda value: field <= value,
|
|
139
|
+
"not": lambda value: field != value
|
|
140
|
+
}
|
|
141
|
+
yield from create_query_fields(
|
|
142
|
+
base_field,
|
|
143
|
+
field_name,
|
|
144
|
+
annotation,
|
|
145
|
+
operator_mapping,
|
|
146
|
+
json_schema_extra
|
|
147
|
+
)
|
|
148
|
+
elif is_enum(annotation):
|
|
149
|
+
operator_mapping = {
|
|
150
|
+
None: lambda value: field == value,
|
|
151
|
+
"not": lambda value: field != value
|
|
120
152
|
}
|
|
121
153
|
yield from create_query_fields(
|
|
122
154
|
base_field,
|
|
@@ -124,7 +156,7 @@ def create_callback(
|
|
|
124
156
|
annotation,
|
|
125
157
|
operator_mapping,
|
|
126
158
|
json_schema_extra
|
|
127
|
-
)
|
|
159
|
+
)
|
|
128
160
|
sort_name = f"sort_{field_name}"
|
|
129
161
|
sort_name_dot = f"sort.{field_name}"
|
|
130
162
|
yield (
|
|
@@ -134,9 +166,7 @@ def create_callback(
|
|
|
134
166
|
alias=sort_name_dot,
|
|
135
167
|
validation_alias=AliasChoices(sort_name, sort_name_dot),
|
|
136
168
|
default=None,
|
|
137
|
-
json_schema_extra=json_schema_extra
|
|
138
|
-
"query.backend": "sql"
|
|
139
|
-
}
|
|
169
|
+
json_schema_extra=json_schema_extra
|
|
140
170
|
),
|
|
141
171
|
DefaultSort
|
|
142
172
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{querymodelling-0.0.2a0 → querymodelling-0.0.4}/querymodelling.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|