scruby 0.11.1__py3-none-any.whl → 0.12.2__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
|
@@ -11,7 +11,7 @@ import zlib
|
|
|
11
11
|
from collections.abc import Callable
|
|
12
12
|
from pathlib import Path as SyncPath
|
|
13
13
|
from shutil import rmtree
|
|
14
|
-
from typing import Any, Never, TypeVar, assert_never
|
|
14
|
+
from typing import Any, Literal, Never, TypeVar, assert_never
|
|
15
15
|
|
|
16
16
|
import orjson
|
|
17
17
|
from anyio import Path, to_thread
|
|
@@ -123,7 +123,7 @@ class Scruby[T]:
|
|
|
123
123
|
meta_json = meta.model_dump_json()
|
|
124
124
|
await meta_path.write_text(meta_json, "utf-8")
|
|
125
125
|
|
|
126
|
-
async def _counter_documents(self,
|
|
126
|
+
async def _counter_documents(self, step: Literal[1, -1]) -> None:
|
|
127
127
|
"""Asynchronous method for management of documents in metadata of collection.
|
|
128
128
|
|
|
129
129
|
This method is for internal use.
|
|
@@ -131,9 +131,7 @@ class Scruby[T]:
|
|
|
131
131
|
meta_path = await self._get_meta_path()
|
|
132
132
|
meta_json = await meta_path.read_text("utf-8")
|
|
133
133
|
meta: _Meta = self.__meta.model_validate_json(meta_json)
|
|
134
|
-
meta.counter_documents +=
|
|
135
|
-
if meta.counter_documents < 0:
|
|
136
|
-
meta.counter_documents = 0
|
|
134
|
+
meta.counter_documents += step
|
|
137
135
|
meta_json = meta.model_dump_json()
|
|
138
136
|
await meta_path.write_text(meta_json, "utf-8")
|
|
139
137
|
|
|
@@ -156,8 +154,6 @@ class Scruby[T]:
|
|
|
156
154
|
meta_json = meta_path.read_text("utf-8")
|
|
157
155
|
meta: _Meta = self.__meta.model_validate_json(meta_json)
|
|
158
156
|
meta.counter_documents += number
|
|
159
|
-
if meta.counter_documents < 0:
|
|
160
|
-
meta.counter_documents = 0
|
|
161
157
|
meta_json = meta.model_dump_json()
|
|
162
158
|
meta_path.write_text(meta_json, "utf-8")
|
|
163
159
|
|
|
@@ -467,7 +463,7 @@ class Scruby[T]:
|
|
|
467
463
|
def _task_delete(
|
|
468
464
|
branch_number: int,
|
|
469
465
|
filter_fn: Callable,
|
|
470
|
-
hash_reduce_left:
|
|
466
|
+
hash_reduce_left: int,
|
|
471
467
|
db_root: str,
|
|
472
468
|
class_model: T,
|
|
473
469
|
) -> int:
|
|
@@ -539,3 +535,48 @@ class Scruby[T]:
|
|
|
539
535
|
if counter < 0:
|
|
540
536
|
self._sync_counter_documents(counter)
|
|
541
537
|
return abs(counter)
|
|
538
|
+
|
|
539
|
+
@staticmethod
|
|
540
|
+
def _task_get_docs(
|
|
541
|
+
branch_number: int,
|
|
542
|
+
hash_reduce_left: int,
|
|
543
|
+
db_root: str,
|
|
544
|
+
class_model: T,
|
|
545
|
+
) -> list[Any]:
|
|
546
|
+
"""Get documents for custom task.
|
|
547
|
+
|
|
548
|
+
This method is for internal use.
|
|
549
|
+
"""
|
|
550
|
+
branch_number_as_hash: str = f"{branch_number:08x}"[hash_reduce_left:]
|
|
551
|
+
separated_hash: str = "/".join(list(branch_number_as_hash))
|
|
552
|
+
leaf_path: SyncPath = SyncPath(
|
|
553
|
+
*(
|
|
554
|
+
db_root,
|
|
555
|
+
class_model.__name__,
|
|
556
|
+
separated_hash,
|
|
557
|
+
"leaf.json",
|
|
558
|
+
),
|
|
559
|
+
)
|
|
560
|
+
docs = []
|
|
561
|
+
if leaf_path.exists():
|
|
562
|
+
data_json: bytes = leaf_path.read_bytes()
|
|
563
|
+
data: dict[str, str] = orjson.loads(data_json) or {}
|
|
564
|
+
for _, val in data.items():
|
|
565
|
+
docs.append(class_model.model_validate_json(val))
|
|
566
|
+
return docs
|
|
567
|
+
|
|
568
|
+
def run_custom_task(self, custom_task: Callable) -> Any:
|
|
569
|
+
"""Running custom task.
|
|
570
|
+
|
|
571
|
+
This method running a task created on the basis of a quantum loop.
|
|
572
|
+
Effectiveness running task depends on the number of processor threads.
|
|
573
|
+
Ideally, hundreds and even thousands of threads are required.
|
|
574
|
+
"""
|
|
575
|
+
kwargs = {
|
|
576
|
+
"get_docs_fn": self._task_get_docs,
|
|
577
|
+
"branch_numbers": range(1, self.__max_branch_number),
|
|
578
|
+
"hash_reduce_left": self.__hash_reduce_left,
|
|
579
|
+
"db_root": self.__db_root,
|
|
580
|
+
"class_model": self.__class_model,
|
|
581
|
+
}
|
|
582
|
+
return custom_task(**kwargs)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.2
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
3
|
+
scruby/db.py,sha256=-xNn0S2fcIQoar4fYk6ER2p7dlDIeUY-BAD6LLYtFFo,21733
|
|
4
4
|
scruby/errors.py,sha256=aHQri4LNcFVQrSHwjyzb1fL8O49SwjYEU4QgMOo4uyA,622
|
|
5
5
|
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
scruby-0.
|
|
7
|
-
scruby-0.
|
|
8
|
-
scruby-0.
|
|
9
|
-
scruby-0.
|
|
6
|
+
scruby-0.12.2.dist-info/METADATA,sha256=YK-ZgnJEcS7y0R27hh7GTlRSAexq5H9olStIQKZL7sc,10925
|
|
7
|
+
scruby-0.12.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
scruby-0.12.2.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
9
|
+
scruby-0.12.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|