scruby 0.8.1__py3-none-any.whl → 0.9.1__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/__init__.py CHANGED
@@ -18,4 +18,12 @@ from __future__ import annotations
18
18
 
19
19
  __all__ = ("Scruby",)
20
20
 
21
+ import logging
22
+
21
23
  from scruby.db import Scruby
24
+
25
+ logging.basicConfig(
26
+ level=logging.INFO,
27
+ datefmt="%Y-%m-%d %H:%M:%S",
28
+ format="[%(asctime)s.%(msecs)03d] %(module)10s:%(lineno)-3d %(levelname)-7s - %(message)s",
29
+ )
scruby/db.py CHANGED
@@ -6,6 +6,7 @@ __all__ = ("Scruby",)
6
6
 
7
7
  import concurrent.futures
8
8
  import contextlib
9
+ import logging
9
10
  import zlib
10
11
  from collections.abc import Callable
11
12
  from pathlib import Path as SyncPath
@@ -17,6 +18,8 @@ from anyio import Path, to_thread
17
18
 
18
19
  from scruby import constants
19
20
 
21
+ logger = logging.getLogger(__name__)
22
+
20
23
  T = TypeVar("T")
21
24
 
22
25
 
@@ -45,6 +48,8 @@ class Scruby[T]:
45
48
  case 6:
46
49
  self.__max_num_keys = 256
47
50
  case _ as unreachable:
51
+ msg: str = f"{unreachable} - Unacceptable value for LENGTH_REDUCTION_HASH."
52
+ logger.critical(msg)
48
53
  assert_never(Never(unreachable))
49
54
 
50
55
  async def get_leaf_path(self, key: str) -> Path:
@@ -54,8 +59,10 @@ class Scruby[T]:
54
59
  key: Key name.
55
60
  """
56
61
  if not isinstance(key, str):
62
+ logger.error("The key is not a type of `str`.")
57
63
  raise KeyError("The key is not a type of `str`.")
58
64
  if len(key) == 0:
65
+ logger.error("The key should not be empty.")
59
66
  raise KeyError("The key should not be empty.")
60
67
  # Key to crc32 sum.
61
68
  key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[self.__length_reduction_hash :]
@@ -115,6 +122,8 @@ class Scruby[T]:
115
122
  data: dict = orjson.loads(data_json) or {}
116
123
  obj: T = self.__class_model.model_validate_json(data[key])
117
124
  return obj
125
+ msg: str = "`get_key` - The unacceptable key value."
126
+ logger.error(msg)
118
127
  raise KeyError()
119
128
 
120
129
  async def has_key(self, key: str) -> bool:
@@ -151,6 +160,8 @@ class Scruby[T]:
151
160
  del data[key]
152
161
  await leaf_path.write_bytes(orjson.dumps(data))
153
162
  return
163
+ msg: str = "`delete_key` - The unacceptable key value."
164
+ logger.error(msg)
154
165
  raise KeyError()
155
166
 
156
167
  @staticmethod
@@ -200,7 +211,7 @@ class Scruby[T]:
200
211
  max_workers: int | None = None,
201
212
  timeout: float | None = None,
202
213
  ) -> T | None:
203
- """Find a single document.
214
+ """Find a single document matching the filter.
204
215
 
205
216
  The search is based on the effect of a quantum loop.
206
217
  The search effectiveness depends on the number of processor threads.
@@ -241,7 +252,7 @@ class Scruby[T]:
241
252
  max_workers: int | None = None,
242
253
  timeout: float | None = None,
243
254
  ) -> list[T] | None:
244
- """Find documents.
255
+ """Find one or more documents matching the filter.
245
256
 
246
257
  The search is based on the effect of a quantum loop.
247
258
  The search effectiveness depends on the number of processor threads.
@@ -280,3 +291,11 @@ class Scruby[T]:
280
291
  results.append(doc)
281
292
  counter += 1
282
293
  return results or None
294
+
295
+ def collection_name(self) -> str:
296
+ """Get collection name."""
297
+ return self.__class_model.__name__
298
+
299
+ def collection_full_name(self) -> str:
300
+ """Get full name of collection."""
301
+ return f"{self.__db_root}/{self.__class_model.__name__}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 0.8.1
3
+ Version: 0.9.1
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
@@ -103,6 +103,8 @@ uv add scruby
103
103
 
104
104
  ## Usage
105
105
 
106
+ See more examples here [https://kebasyaty.github.io/scruby/latest/pages/usage/](https://kebasyaty.github.io/scruby/latest/pages/usage/ "Examples").
107
+
106
108
  ```python
107
109
  """Working with keys."""
108
110
 
@@ -0,0 +1,8 @@
1
+ scruby/__init__.py,sha256=wFwUS1KcLxfIopXOVS8gPue9fNzIIU2cVj_RgK5drz4,849
2
+ scruby/constants.py,sha256=GbB-O0qaVdi5EHUp-zRAppFXLR-oHxpXUFVAOCpS0C8,1022
3
+ scruby/db.py,sha256=W3VvC3ss1NXonQnFI6Yw2MobBARMgus5Acw-k5uL3TE,10946
4
+ scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ scruby-0.9.1.dist-info/METADATA,sha256=jBb7hXf3Ho3y0MGtsTc-3d4ip7xEse9I27XjPspFnbg,10781
6
+ scruby-0.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ scruby-0.9.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
+ scruby-0.9.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
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.1.dist-info/METADATA,sha256=TpqA2Ukl-TnolmTr-mRTRIFGE2KcKdzm8tLP1xRWKFM,10632
6
- scruby-0.8.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- scruby-0.8.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
- scruby-0.8.1.dist-info/RECORD,,
File without changes