scruby 0.11.1__py3-none-any.whl → 0.12.0__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 scruby might be problematic. Click here for more details.

scruby/db.py CHANGED
@@ -467,7 +467,7 @@ class Scruby[T]:
467
467
  def _task_delete(
468
468
  branch_number: int,
469
469
  filter_fn: Callable,
470
- hash_reduce_left: str,
470
+ hash_reduce_left: int,
471
471
  db_root: str,
472
472
  class_model: T,
473
473
  ) -> int:
@@ -539,3 +539,48 @@ class Scruby[T]:
539
539
  if counter < 0:
540
540
  self._sync_counter_documents(counter)
541
541
  return abs(counter)
542
+
543
+ @staticmethod
544
+ def _task_get_docs(
545
+ branch_number: int,
546
+ hash_reduce_left: int,
547
+ db_root: str,
548
+ class_model: T,
549
+ ) -> list[Any]:
550
+ """Get documents for custom task.
551
+
552
+ This method is for internal use.
553
+ """
554
+ branch_number_as_hash: str = f"{branch_number:08x}"[hash_reduce_left:]
555
+ separated_hash: str = "/".join(list(branch_number_as_hash))
556
+ leaf_path: SyncPath = SyncPath(
557
+ *(
558
+ db_root,
559
+ class_model.__name__,
560
+ separated_hash,
561
+ "leaf.json",
562
+ ),
563
+ )
564
+ docs = []
565
+ if leaf_path.exists():
566
+ data_json: bytes = leaf_path.read_bytes()
567
+ data: dict[str, str] = orjson.loads(data_json) or {}
568
+ for _, val in data.items():
569
+ docs.append(class_model.model_validate_json(val))
570
+ return docs
571
+
572
+ def run_custom_task(self, custom_task: Callable) -> Any:
573
+ """Running custom task.
574
+
575
+ This method running a task created on the basis of a quantum loop.
576
+ Effectiveness running task depends on the number of processor threads.
577
+ Ideally, hundreds and even thousands of threads are required.
578
+ """
579
+ kwargs = {
580
+ "get_docs_fn": self._task_get_docs,
581
+ "branch_numbers": range(1, self.__max_branch_number),
582
+ "hash_reduce_left": self.__hash_reduce_left,
583
+ "db_root": self.__db_root,
584
+ "class_model": self.__class_model,
585
+ }
586
+ return custom_task(**kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 0.11.1
3
+ Version: 0.12.0
4
4
  Summary: A fast key-value storage library.
5
5
  Project-URL: Homepage, https://github.com/kebasyaty/scruby
6
6
  Project-URL: Repository, https://github.com/kebasyaty/scruby
@@ -120,6 +120,7 @@ from scruby import Scruby, constants
120
120
 
121
121
  constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
122
122
 
123
+
123
124
  class User(BaseModel):
124
125
  """Model of User."""
125
126
  first_name: str
@@ -128,6 +129,7 @@ class User(BaseModel):
128
129
  email: EmailStr
129
130
  phone: Annotated[PhoneNumber, PhoneNumberValidator(number_format="E164")]
130
131
 
132
+
131
133
  async def main() -> None:
132
134
  """Example."""
133
135
  # Get collection of `User`.
@@ -157,6 +159,7 @@ async def main() -> None:
157
159
  # Hint: The main purpose is tests.
158
160
  await Scruby.napalm()
159
161
 
162
+
160
163
  if __name__ == "__main__":
161
164
  anyio.run(main)
162
165
  ```
@@ -179,7 +182,8 @@ from pprint import pprint as pp
179
182
 
180
183
  constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
181
184
  constants.HASH_REDUCE_LEFT = 6 # 256 branches in collection
182
- # (main purpose is tests).
185
+ # (main purpose is tests).
186
+
183
187
 
184
188
  class User(BaseModel):
185
189
  """Model of User."""
@@ -189,6 +193,7 @@ class User(BaseModel):
189
193
  email: EmailStr
190
194
  phone: Annotated[PhoneNumber, PhoneNumberValidator(number_format="E164")]
191
195
 
196
+
192
197
  async def main() -> None:
193
198
  """Example."""
194
199
  # Get collection of `User`.
@@ -228,6 +233,7 @@ async def main() -> None:
228
233
  # Hint: The main purpose is tests.
229
234
  await Scruby.napalm()
230
235
 
236
+
231
237
  if __name__ == "__main__":
232
238
  anyio.run(main)
233
239
  ```
@@ -250,7 +256,8 @@ from pprint import pprint as pp
250
256
 
251
257
  constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
252
258
  constants.HASH_REDUCE_LEFT = 6 # 256 branches in collection
253
- # (main purpose is tests).
259
+ # (main purpose is tests).
260
+
254
261
 
255
262
  class User(BaseModel):
256
263
  """Model of User."""
@@ -260,6 +267,7 @@ class User(BaseModel):
260
267
  email: EmailStr
261
268
  phone: Annotated[PhoneNumber, PhoneNumberValidator(number_format="E164")]
262
269
 
270
+
263
271
  async def main() -> None:
264
272
  """Example."""
265
273
  # Get collection of `User`.
@@ -289,6 +297,7 @@ async def main() -> None:
289
297
  # Hint: The main purpose is tests.
290
298
  await Scruby.napalm()
291
299
 
300
+
292
301
  if __name__ == "__main__":
293
302
  anyio.run(main)
294
303
  ```
@@ -1,9 +1,9 @@
1
1
  scruby/__init__.py,sha256=GOVcjXmcOEDBbJQJDJlQq-x3M-VGJaMSN278EXsl2po,884
2
2
  scruby/constants.py,sha256=3LZfcxcuRqwzoB0-iogLMjKBZRdxfWJmTbyPwVRhQgY,1007
3
- scruby/db.py,sha256=Q7J4OKS2emiF0KzZClSjpBBLjohnccZ81T4pgoWNxqA,20269
3
+ scruby/db.py,sha256=fFJKCvvDmHKXzQubghG2DoRV7xumd460sHGqCDCCgh0,21877
4
4
  scruby/errors.py,sha256=aHQri4LNcFVQrSHwjyzb1fL8O49SwjYEU4QgMOo4uyA,622
5
5
  scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- scruby-0.11.1.dist-info/METADATA,sha256=Dn9WBqLzI312HlhMx4PGIVpmysCc6IUSPqXjXDuAOQY,10926
7
- scruby-0.11.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
- scruby-0.11.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
9
- scruby-0.11.1.dist-info/RECORD,,
6
+ scruby-0.12.0.dist-info/METADATA,sha256=Ok-HJBIDsQ-DktJRjoIORaC91Vbc8qt9UPc-VN9k57Q,10925
7
+ scruby-0.12.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8
+ scruby-0.12.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
9
+ scruby-0.12.0.dist-info/RECORD,,