scruby 2.6.2__py3-none-any.whl → 2.6.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.
- scruby/mixins/find.py +23 -5
- {scruby-2.6.2.dist-info → scruby-2.6.4.dist-info}/METADATA +3 -1
- {scruby-2.6.2.dist-info → scruby-2.6.4.dist-info}/RECORD +6 -6
- {scruby-2.6.2.dist-info → scruby-2.6.4.dist-info}/WHEEL +0 -0
- {scruby-2.6.2.dist-info → scruby-2.6.4.dist-info}/licenses/GPL-3.0-LICENSE +0 -0
- {scruby-2.6.2.dist-info → scruby-2.6.4.dist-info}/licenses/MIT-LICENSE +0 -0
scruby/mixins/find.py
CHANGED
|
@@ -19,7 +19,7 @@ from scruby.cache import DocCache
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class ReturnType(Enum):
|
|
22
|
-
"""Return type.
|
|
22
|
+
"""Return type for a find_one and find_many methods.
|
|
23
23
|
|
|
24
24
|
Members:
|
|
25
25
|
- `MODEL:` ScrubyModel type.
|
|
@@ -82,6 +82,8 @@ class Find:
|
|
|
82
82
|
def find_one(
|
|
83
83
|
self,
|
|
84
84
|
filter_fn: Callable,
|
|
85
|
+
include_fields: set[str] | None = None,
|
|
86
|
+
exclude_fields: set[str] | None = None,
|
|
85
87
|
return_type: ReturnType = ReturnType.MODEL,
|
|
86
88
|
) -> Any | None:
|
|
87
89
|
"""Synchronous method for find one document matching the filter.
|
|
@@ -92,6 +94,10 @@ class Find:
|
|
|
92
94
|
|
|
93
95
|
Args:
|
|
94
96
|
filter_fn (Callable): A function that execute the conditions of filtering.
|
|
97
|
+
include_fields: (set[str] | None): A set of fields to include in the output.
|
|
98
|
+
Available for `ReturnType.JSON` and `ReturnType.DICT`.
|
|
99
|
+
exclude_fields: (set[str] | None): A set of fields to exclude from the output.
|
|
100
|
+
Available for `ReturnType.JSON` and `ReturnType.DICT`.
|
|
95
101
|
return_type (ReturnType): ScrubyModel, JSON-string or Dictionary.
|
|
96
102
|
|
|
97
103
|
Returns:
|
|
@@ -101,6 +107,7 @@ class Find:
|
|
|
101
107
|
hash_reduce_left: int = self._hash_reduce_left
|
|
102
108
|
assert hash_reduce_left != 0, "Scruby.run(hash_reduce_left = 0) - Not valid for `find_one` method."
|
|
103
109
|
|
|
110
|
+
model_dump_kwargs = {"include": include_fields, "exclude": exclude_fields}
|
|
104
111
|
search_task_fn: Callable = self._task_find
|
|
105
112
|
branch_numbers: range = range(self._max_number_branch)
|
|
106
113
|
class_model: Any = self._class_model
|
|
@@ -136,9 +143,9 @@ class Find:
|
|
|
136
143
|
case 1:
|
|
137
144
|
return doc
|
|
138
145
|
case 2:
|
|
139
|
-
return doc.model_dump_json() if doc is not None else None
|
|
146
|
+
return doc.model_dump_json(**model_dump_kwargs) if doc is not None else None
|
|
140
147
|
case 3:
|
|
141
|
-
return doc.model_dump() if doc is not None else None
|
|
148
|
+
return doc.model_dump(**model_dump_kwargs) if doc is not None else None
|
|
142
149
|
case _ as unreachable:
|
|
143
150
|
assert_never(Never(unreachable)) # pyrefly: ignore[not-callable]
|
|
144
151
|
|
|
@@ -150,6 +157,8 @@ class Find:
|
|
|
150
157
|
page_number: int = 1,
|
|
151
158
|
sort_fn: Callable | None = lambda doc: doc.created_at,
|
|
152
159
|
sort_reverse: bool = True,
|
|
160
|
+
include_fields: set[str] | None = None,
|
|
161
|
+
exclude_fields: set[str] | None = None,
|
|
153
162
|
return_type: ReturnType = ReturnType.MODEL,
|
|
154
163
|
) -> list[Any] | str | None:
|
|
155
164
|
"""Synchronous method for find many documents matching the filter.
|
|
@@ -170,6 +179,10 @@ class Find:
|
|
|
170
179
|
By default, documents are sorted by creation date.
|
|
171
180
|
sort_reverse: (bool): Sorting direction.
|
|
172
181
|
By default, sort descending (newest to oldest).
|
|
182
|
+
include_fields: (set[str] | None): A set of fields to include in the output.
|
|
183
|
+
Available for `ReturnType.JSON` and `ReturnType.DICT`.
|
|
184
|
+
exclude_fields: (set[str] | None): A set of fields to exclude from the output.
|
|
185
|
+
Available for `ReturnType.JSON` and `ReturnType.DICT`.
|
|
173
186
|
return_type (ReturnType): ScrubyModel, JSON-string or Dictionary.
|
|
174
187
|
|
|
175
188
|
Returns:
|
|
@@ -186,6 +199,7 @@ class Find:
|
|
|
186
199
|
hash_reduce_left: int = self._hash_reduce_left
|
|
187
200
|
assert hash_reduce_left != 0, "Scruby.run(hash_reduce_left = 0) - Not valid for `find_many` method."
|
|
188
201
|
|
|
202
|
+
model_dump_kwargs = {"include": include_fields, "exclude": exclude_fields}
|
|
189
203
|
search_task_fn: Callable = self._task_find
|
|
190
204
|
branch_numbers: range = range(self._max_number_branch)
|
|
191
205
|
class_model: Any = self._class_model
|
|
@@ -235,8 +249,12 @@ class Find:
|
|
|
235
249
|
case 1:
|
|
236
250
|
return result or None
|
|
237
251
|
case 2:
|
|
238
|
-
return
|
|
252
|
+
return (
|
|
253
|
+
f"[{','.join([doc.model_dump_json(**model_dump_kwargs) for doc in result])}]"
|
|
254
|
+
if result is not None
|
|
255
|
+
else None
|
|
256
|
+
)
|
|
239
257
|
case 3:
|
|
240
|
-
return [doc.model_dump() for doc in result] if result is not None else None
|
|
258
|
+
return [doc.model_dump(**model_dump_kwargs) for doc in result] if result is not None else None
|
|
241
259
|
case _ as unreachable:
|
|
242
260
|
assert_never(Never(unreachable)) # pyrefly: ignore[not-callable]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 2.6.
|
|
3
|
+
Version: 2.6.4
|
|
4
4
|
Summary: Asynchronous library for building and managing a hybrid database, by scheme of key-value.
|
|
5
5
|
Project-URL: Bug Tracker, https://github.com/kebasyaty/scruby/issues
|
|
6
6
|
Project-URL: Changelog, https://github.com/kebasyaty/scruby/blob/v2/CHANGELOG.md
|
|
@@ -147,6 +147,7 @@ from scruby import Scruby, ScrubyModel
|
|
|
147
147
|
|
|
148
148
|
class User(ScrubyModel):
|
|
149
149
|
"""User model."""
|
|
150
|
+
username: str
|
|
150
151
|
first_name: str
|
|
151
152
|
last_name: str
|
|
152
153
|
birthday: datetime
|
|
@@ -172,6 +173,7 @@ async def main() -> None:
|
|
|
172
173
|
|
|
173
174
|
# Create user
|
|
174
175
|
user = User(
|
|
176
|
+
username=f"user_1",
|
|
175
177
|
first_name="John",
|
|
176
178
|
last_name="Smith",
|
|
177
179
|
birthday=datetime(1970, 1, 1, tzinfo=ZoneInfo("UTC")),
|
|
@@ -14,11 +14,11 @@ scruby/mixins/collection.py,sha256=mLr6SAFh1XYKEzedsPAEWYyWKG8xSx7OOkGhhfYm3qM,2
|
|
|
14
14
|
scruby/mixins/count.py,sha256=CGpyOpsG25uC5utI2ByNxq2iTbJocj6w5tXrC1_cP40,2561
|
|
15
15
|
scruby/mixins/custom_task.py,sha256=DIry4gBlTdaqZqymar-RrHSdhEiC2tn2pl9jmbk56zw,1547
|
|
16
16
|
scruby/mixins/delete.py,sha256=InKVIud_ZYx9-CchUz_IygQDXMynNi4jQ0HKYeHC_R8,4328
|
|
17
|
-
scruby/mixins/find.py,sha256=
|
|
17
|
+
scruby/mixins/find.py,sha256=MRyBIc4KPibjhHubl7XHmMj4JIBNLXNgsLID_V9jtrw,10488
|
|
18
18
|
scruby/mixins/keys.py,sha256=MvBy_8fQGROaQATK2qse2V8wR-xodPQG0KKZ2PK_t9U,10790
|
|
19
19
|
scruby/mixins/update.py,sha256=TyxvxB-gNijlfzTmhwrq0ydvu0C3R-RihW5h5tJ96bM,4964
|
|
20
|
-
scruby-2.6.
|
|
21
|
-
scruby-2.6.
|
|
22
|
-
scruby-2.6.
|
|
23
|
-
scruby-2.6.
|
|
24
|
-
scruby-2.6.
|
|
20
|
+
scruby-2.6.4.dist-info/METADATA,sha256=6FpVRsUxZ7cIh_EXgxXytv9yM5IKRFoAhfak4ya6kj0,13363
|
|
21
|
+
scruby-2.6.4.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
22
|
+
scruby-2.6.4.dist-info/licenses/GPL-3.0-LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
23
|
+
scruby-2.6.4.dist-info/licenses/MIT-LICENSE,sha256=mS0Wz0yGNB63gEcWEnuIb_lldDYV0sjRaO-o_GL6CWE,1074
|
|
24
|
+
scruby-2.6.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|