scruby 0.7.1__py3-none-any.whl → 0.8.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/constants.py CHANGED
@@ -4,10 +4,10 @@ The module contains the following variables:
4
4
 
5
5
  - `DB_ROOT` - Path to root directory of database. `By default = "ScrubyDB"` (*in root of project*).
6
6
  - `LENGTH_REDUCTION_HASH` - The length of the hash reduction on the left side.
7
- - `0` - 4294967296 keys (by default).
8
- - `2` - 16777216 keys.
9
- - `4` - 65536 keys.
10
- - `6` - 256 keys (main purpose is tests).
7
+ - `0` - 4294967296 branches in collection (by default).
8
+ - `2` - 16777216 branches in collectionю
9
+ - `4` - 65536 branches in collectionю
10
+ - `6` - 256 branches in collection (main purpose is tests).
11
11
  """
12
12
 
13
13
  from __future__ import annotations
@@ -24,8 +24,8 @@ from typing import Literal
24
24
  DB_ROOT: str = "ScrubyDB"
25
25
 
26
26
  # The length of the hash reduction on the left side.
27
- # 0 = 4294967296 keys (by default).
28
- # 2 = 16777216 keys.
29
- # 4 = 65536 keys.
30
- # 6 = 256 keys (main purpose is tests).
27
+ # 0 = 4294967296 branches in collection (by default).
28
+ # 2 = 16777216 branches in collectionю
29
+ # 4 = 65536 branches in collectionю
30
+ # 6 = 256 branches in collection (main purpose is tests).
31
31
  LENGTH_REDUCTION_HASH: Literal[0, 2, 4, 6] = 0
scruby/db.py CHANGED
@@ -204,7 +204,7 @@ class Scruby[T]:
204
204
 
205
205
  The search is based on the effect of a quantum loop.
206
206
  The search effectiveness depends on the number of processor threads.
207
- Ideally, hundreds and even thousands of streams are required.
207
+ Ideally, hundreds and even thousands of threads are required.
208
208
 
209
209
  Args:
210
210
  filter_fn: A function that execute the conditions of filtering.
@@ -229,7 +229,54 @@ class Scruby[T]:
229
229
  db_root,
230
230
  class_model,
231
231
  )
232
- result = future.result(timeout)
233
- if result is not None:
234
- return result
232
+ doc = future.result(timeout)
233
+ if doc is not None:
234
+ return doc
235
235
  return None
236
+
237
+ def find_many(
238
+ self,
239
+ filter_fn: Callable,
240
+ db_query_docs_limit: int = 1000,
241
+ max_workers: int | None = None,
242
+ timeout: float | None = None,
243
+ ) -> list[T] | None:
244
+ """Find documents.
245
+
246
+ The search is based on the effect of a quantum loop.
247
+ The search effectiveness depends on the number of processor threads.
248
+ Ideally, hundreds and even thousands of threads are required.
249
+
250
+ Args:
251
+ filter_fn: A function that execute the conditions of filtering.
252
+ db_query_docs_limit: Limiting the number of request results. By default = 1000.
253
+ max_workers: The maximum number of processes that can be used to
254
+ execute the given calls. If None or not given then as many
255
+ worker processes will be created as the machine has processors.
256
+ timeout: The number of seconds to wait for the result if the future isn't done.
257
+ If None, then there is no limit on the wait time.
258
+ """
259
+ keys: range = range(1, self.__max_num_keys)
260
+ search_task_fn: Callable = self.search_task
261
+ length_reduction_hash: int = self.__length_reduction_hash
262
+ db_root: str = self.__db_root
263
+ class_model: T = self.__class_model
264
+ counter: int = 0
265
+ with concurrent.futures.ThreadPoolExecutor(max_workers) as executor:
266
+ results = []
267
+ for key in keys:
268
+ if counter == db_query_docs_limit:
269
+ break
270
+ future = executor.submit(
271
+ search_task_fn,
272
+ key,
273
+ filter_fn,
274
+ length_reduction_hash,
275
+ db_root,
276
+ class_model,
277
+ )
278
+ doc = future.result(timeout)
279
+ if doc is not None:
280
+ results.append(doc)
281
+ counter += 1
282
+ return results or None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 0.7.1
3
+ Version: 0.8.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
@@ -160,7 +160,7 @@ if __name__ == "__main__":
160
160
 
161
161
  The search is based on the effect of a quantum loop.
162
162
  The search effectiveness depends on the number of processor threads.
163
- Ideally, hundreds and even thousands of streams are required.
163
+ Ideally, hundreds and even thousands of threads are required.
164
164
  """
165
165
 
166
166
  import anyio
@@ -171,7 +171,8 @@ from scruby import Scruby, constants
171
171
  from pprint import pprint as pp
172
172
 
173
173
  constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
174
- constants.LENGTH_REDUCTION_HASH = 6 # 256 keys (main purpose is tests).
174
+ constants.LENGTH_REDUCTION_HASH = 6 # 256 branches in collection
175
+ # (main purpose is tests).
175
176
 
176
177
  class User(BaseModel):
177
178
  """Model of User."""
@@ -224,6 +225,66 @@ if __name__ == "__main__":
224
225
  anyio.run(main)
225
226
  ```
226
227
 
228
+ ```python
229
+ """Find documents.
230
+
231
+ The search is based on the effect of a quantum loop.
232
+ The search effectiveness depends on the number of processor threads.
233
+ Ideally, hundreds and even thousands of threads are required.
234
+ """
235
+
236
+ import anyio
237
+ import datetime
238
+ from pydantic import BaseModel, EmailStr
239
+ from pydantic_extra_types.phone_numbers import PhoneNumber
240
+ from scruby import Scruby, constants
241
+ from pprint import pprint as pp
242
+
243
+ constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
244
+ constants.LENGTH_REDUCTION_HASH = 6 # 256 branches in collection
245
+ # (main purpose is tests).
246
+
247
+ class User(BaseModel):
248
+ """Model of User."""
249
+ first_name: str
250
+ last_name: str
251
+ birthday: datetime.datetime
252
+ email: EmailStr
253
+ phone: PhoneNumber
254
+
255
+ async def main() -> None:
256
+ """Example."""
257
+ # Get collection of `User`.
258
+ user_coll = Scruby(User)
259
+
260
+ # Create users.
261
+ for num in range(1, 10):
262
+ user = User(
263
+ first_name="John",
264
+ last_name="Smith",
265
+ birthday=datetime.datetime(1970, 1, num),
266
+ email=f"John_Smith_{num}@gmail.com",
267
+ phone=f"+44798612345{num}",
268
+ )
269
+ await db.set_key(f"+44798612345{num}", user)
270
+
271
+ # Find users by email.
272
+ users: list[User] | None = user_coll.find_many(
273
+ filter_fn=lambda doc: doc.email == "John_Smith_5@gmail.com" or doc.email == "John_Smith_8@gmail.com",
274
+ )
275
+ if users is not None:
276
+ pp(users)
277
+ else:
278
+ print("No users!")
279
+
280
+ # Full database deletion.
281
+ # Hint: The main purpose is tests.
282
+ await Scruby.napalm()
283
+
284
+ if __name__ == "__main__":
285
+ anyio.run(main)
286
+ ```
287
+
227
288
  ## Changelog
228
289
 
229
290
  [View the change history](https://github.com/kebasyaty/scruby/blob/v0/CHANGELOG.md "Changelog").
@@ -0,0 +1,8 @@
1
+ scruby/__init__.py,sha256=myX7sG-7oAQZGdgfZtTGXYCCraTeuwi7SjBoltftpnM,648
2
+ scruby/constants.py,sha256=GbB-O0qaVdi5EHUp-zRAppFXLR-oHxpXUFVAOCpS0C8,1022
3
+ scruby/db.py,sha256=FWCrcpzP93V1fk7NXhp6x2UgGkwqvk7qXvphm38R0X8,10130
4
+ scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ scruby-0.8.0.dist-info/METADATA,sha256=Ktsxx4l5cmeVST2tzADKs7Hazi3WD1zjSS53QVpyJY8,10314
6
+ scruby-0.8.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ scruby-0.8.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
+ scruby-0.8.0.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- scruby/__init__.py,sha256=myX7sG-7oAQZGdgfZtTGXYCCraTeuwi7SjBoltftpnM,648
2
- scruby/constants.py,sha256=XcBbK_gkDC0makWE34M8gUotwj3smi2sWY4mMnfzUt4,874
3
- scruby/db.py,sha256=FkYBsVYERtauTlWjl8b8cDTTIaH1w7lOzAneWUtNLDE,8114
4
- scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- scruby-0.7.1.dist-info/METADATA,sha256=qkiNaSRnF2pnWMImFLsAz16MMRD_amaDImy9DbFwNoM,8616
6
- scruby-0.7.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- scruby-0.7.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
- scruby-0.7.1.dist-info/RECORD,,
File without changes