scruby 0.6.1__py3-none-any.whl → 0.6.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/__init__.py +1 -5
- scruby/constants.py +13 -1
- scruby/db.py +14 -12
- {scruby-0.6.1.dist-info → scruby-0.6.2.dist-info}/METADATA +4 -2
- scruby-0.6.2.dist-info/RECORD +8 -0
- scruby-0.6.1.dist-info/RECORD +0 -8
- {scruby-0.6.1.dist-info → scruby-0.6.2.dist-info}/WHEEL +0 -0
- {scruby-0.6.1.dist-info → scruby-0.6.2.dist-info}/licenses/LICENSE +0 -0
scruby/__init__.py
CHANGED
|
@@ -16,10 +16,6 @@ In the future, to search by value of key, the use of a quantum loop is supposed.
|
|
|
16
16
|
|
|
17
17
|
from __future__ import annotations
|
|
18
18
|
|
|
19
|
-
__all__ = (
|
|
20
|
-
"Scruby",
|
|
21
|
-
"constants",
|
|
22
|
-
)
|
|
19
|
+
__all__ = ("Scruby",)
|
|
23
20
|
|
|
24
|
-
from scruby import constants
|
|
25
21
|
from scruby.db import Scruby
|
scruby/constants.py
CHANGED
|
@@ -3,9 +3,21 @@
|
|
|
3
3
|
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
|
+
- `LENGTH_SEPARATED_HASH` - Length of separated hash for create path inside collection.
|
|
6
7
|
"""
|
|
7
8
|
|
|
8
9
|
from __future__ import annotations
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
from typing import Literal
|
|
12
|
+
|
|
13
|
+
# Path to root directory of database
|
|
14
|
+
# By default = "ScrubyDB" (in root of project).
|
|
11
15
|
DB_ROOT: str = "ScrubyDB"
|
|
16
|
+
|
|
17
|
+
# Length of separated hash for create path inside collection.
|
|
18
|
+
# By default = 8
|
|
19
|
+
# 2 = 256 branche (main purpose is tests).
|
|
20
|
+
# 4 = 65536 branche.
|
|
21
|
+
# 6 = 16777216 branche.
|
|
22
|
+
# 8 = 4294967296 branche (by default).
|
|
23
|
+
LENGTH_SEPARATED_HASH: Literal[2, 4, 6, 8] = 8
|
scruby/db.py
CHANGED
|
@@ -18,7 +18,7 @@ T = TypeVar("T")
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class Scruby[T]:
|
|
21
|
-
"""Creation and management of
|
|
21
|
+
"""Creation and management of database.
|
|
22
22
|
|
|
23
23
|
Args:
|
|
24
24
|
class_model: Class of Model (Pydantic).
|
|
@@ -31,7 +31,7 @@ class Scruby[T]:
|
|
|
31
31
|
self.__class_model = class_model
|
|
32
32
|
|
|
33
33
|
async def get_leaf_path(self, key: str) -> Path:
|
|
34
|
-
"""
|
|
34
|
+
"""Asynchronous method for getting path to collection cell by key.
|
|
35
35
|
|
|
36
36
|
Args:
|
|
37
37
|
key: Key name.
|
|
@@ -40,16 +40,18 @@ class Scruby[T]:
|
|
|
40
40
|
raise KeyError("The key is not a type of `str`.")
|
|
41
41
|
if len(key) == 0:
|
|
42
42
|
raise KeyError("The key should not be empty.")
|
|
43
|
-
#
|
|
44
|
-
|
|
45
|
-
#
|
|
46
|
-
|
|
43
|
+
# Get length of hash.
|
|
44
|
+
length_hash = constants.LENGTH_SEPARATED_HASH
|
|
45
|
+
# Key to crc32 sum.
|
|
46
|
+
key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[0:length_hash]
|
|
47
|
+
# Convert crc32 sum in the segment of path.
|
|
48
|
+
separated_hash: str = "/".join(list(key_as_hash))
|
|
47
49
|
# The path of the branch to the database.
|
|
48
50
|
branch_path: Path = Path(
|
|
49
51
|
*(
|
|
50
52
|
constants.DB_ROOT,
|
|
51
53
|
self.__class_model.__name__,
|
|
52
|
-
|
|
54
|
+
separated_hash,
|
|
53
55
|
),
|
|
54
56
|
)
|
|
55
57
|
# If the branch does not exist, need to create it.
|
|
@@ -64,7 +66,7 @@ class Scruby[T]:
|
|
|
64
66
|
key: str,
|
|
65
67
|
value: T,
|
|
66
68
|
) -> None:
|
|
67
|
-
"""Asynchronous method for adding and updating keys to
|
|
69
|
+
"""Asynchronous method for adding and updating keys to collection.
|
|
68
70
|
|
|
69
71
|
Args:
|
|
70
72
|
key: Key name.
|
|
@@ -85,7 +87,7 @@ class Scruby[T]:
|
|
|
85
87
|
await leaf_path.write_bytes(orjson.dumps({key: value_json}))
|
|
86
88
|
|
|
87
89
|
async def get_key(self, key: str) -> T:
|
|
88
|
-
"""Asynchronous method for getting key from
|
|
90
|
+
"""Asynchronous method for getting value of key from collection.
|
|
89
91
|
|
|
90
92
|
Args:
|
|
91
93
|
key: Key name.
|
|
@@ -101,7 +103,7 @@ class Scruby[T]:
|
|
|
101
103
|
raise KeyError()
|
|
102
104
|
|
|
103
105
|
async def has_key(self, key: str) -> bool:
|
|
104
|
-
"""Asynchronous method for checking presence of
|
|
106
|
+
"""Asynchronous method for checking presence of key in collection.
|
|
105
107
|
|
|
106
108
|
Args:
|
|
107
109
|
key: Key name.
|
|
@@ -120,7 +122,7 @@ class Scruby[T]:
|
|
|
120
122
|
return False
|
|
121
123
|
|
|
122
124
|
async def delete_key(self, key: str) -> None:
|
|
123
|
-
"""Asynchronous method for deleting key from
|
|
125
|
+
"""Asynchronous method for deleting key from collection.
|
|
124
126
|
|
|
125
127
|
Args:
|
|
126
128
|
key: Key name.
|
|
@@ -138,7 +140,7 @@ class Scruby[T]:
|
|
|
138
140
|
|
|
139
141
|
@classmethod
|
|
140
142
|
async def napalm(cls) -> None:
|
|
141
|
-
"""Asynchronous method for full database deletion
|
|
143
|
+
"""Asynchronous method for full database deletion.
|
|
142
144
|
|
|
143
145
|
The main purpose is tests.
|
|
144
146
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.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
|
|
@@ -65,7 +65,9 @@ Description-Content-Type: text/markdown
|
|
|
65
65
|
<a href="https://github.com/kebasyaty/scruby/releases/" alt="GitHub release"><img src="https://img.shields.io/github/release/kebasyaty/scruby" alt="GitHub release"></a>
|
|
66
66
|
</p>
|
|
67
67
|
<p align="center">
|
|
68
|
-
Scruby is a fast key-value storage asynchronous library that provides an
|
|
68
|
+
Scruby is a fast key-value storage asynchronous library that provides an
|
|
69
|
+
<br>
|
|
70
|
+
ordered mapping from string keys to string values.
|
|
69
71
|
<br>
|
|
70
72
|
The library uses fractal-tree addressing.
|
|
71
73
|
<br>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
scruby/__init__.py,sha256=myX7sG-7oAQZGdgfZtTGXYCCraTeuwi7SjBoltftpnM,648
|
|
2
|
+
scruby/constants.py,sha256=fQ9fHGkx1GwYWOdTCdwopYIVtwYWDi8evLOJtQcTtWg,711
|
|
3
|
+
scruby/db.py,sha256=Rt9YDe0lSJwtREHFiqdQ6CQ664FL6YRyczbgKFhpsa4,4871
|
|
4
|
+
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
scruby-0.6.2.dist-info/METADATA,sha256=Xql1qXX22lzjh67vvN63EoTOxdaUzn4sz99lTGalSy0,6803
|
|
6
|
+
scruby-0.6.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
scruby-0.6.2.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
scruby-0.6.2.dist-info/RECORD,,
|
scruby-0.6.1.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
scruby/__init__.py,sha256=Bhg7pIV6u0YM7Dipr7vH7ka931bVuBoJugiYNd73HQ4,704
|
|
2
|
-
scruby/constants.py,sha256=kwF0FIbeChBxsNxOCQhMsDEn1lakD7MIQKJ-PHYeSAo,328
|
|
3
|
-
scruby/db.py,sha256=qhVoSMu-MDiIdPK4M3ruEZDXxcvKBPu-AS-J_xSNZE4,4763
|
|
4
|
-
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
scruby-0.6.1.dist-info/METADATA,sha256=qzdPamjqOufrJ7hibG37MaiUV27RAIcPikn9idMIYzg,6786
|
|
6
|
-
scruby-0.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
scruby-0.6.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
-
scruby-0.6.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|