scruby 0.4.0__py3-none-any.whl → 0.5.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/__init__.py +5 -1
- scruby/constants.py +11 -0
- scruby/db.py +9 -12
- {scruby-0.4.0.dist-info → scruby-0.5.0.dist-info}/METADATA +15 -18
- scruby-0.5.0.dist-info/RECORD +8 -0
- scruby-0.4.0.dist-info/RECORD +0 -7
- {scruby-0.4.0.dist-info → scruby-0.5.0.dist-info}/WHEEL +0 -0
- {scruby-0.4.0.dist-info → scruby-0.5.0.dist-info}/licenses/LICENSE +0 -0
scruby/__init__.py
CHANGED
|
@@ -12,6 +12,10 @@ There is no need to iterate through all the keys in search of the desired value.
|
|
|
12
12
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
|
-
__all__ = (
|
|
15
|
+
__all__ = (
|
|
16
|
+
"Scruby",
|
|
17
|
+
"constants",
|
|
18
|
+
)
|
|
16
19
|
|
|
20
|
+
from scruby import constants
|
|
17
21
|
from scruby.db import Scruby
|
scruby/constants.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Constant variables.
|
|
2
|
+
|
|
3
|
+
The module contains the following variables:
|
|
4
|
+
|
|
5
|
+
- `DB_ROOT` - Path to root directory of database. By default = "ScrubyDB" (in root of project).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
# Path to root directory of database. By default = "ScrubyDB" (in root of project).
|
|
11
|
+
DB_ROOT: str = "ScrubyDB"
|
scruby/db.py
CHANGED
|
@@ -6,33 +6,28 @@ __all__ = ("Scruby",)
|
|
|
6
6
|
|
|
7
7
|
import hashlib
|
|
8
8
|
from shutil import rmtree
|
|
9
|
-
from typing import
|
|
9
|
+
from typing import TypeVar
|
|
10
10
|
|
|
11
11
|
import orjson
|
|
12
12
|
from anyio import Path, to_thread
|
|
13
13
|
|
|
14
|
+
from scruby import constants
|
|
15
|
+
|
|
14
16
|
T = TypeVar("T")
|
|
15
17
|
|
|
16
18
|
|
|
17
|
-
class Scruby
|
|
19
|
+
class Scruby[T]:
|
|
18
20
|
"""Creation and management of the database.
|
|
19
21
|
|
|
20
22
|
Args:
|
|
21
|
-
|
|
23
|
+
class_model: Class of Model (Pydantic).
|
|
22
24
|
"""
|
|
23
25
|
|
|
24
26
|
def __init__( # noqa: D107
|
|
25
27
|
self,
|
|
26
28
|
class_model: T,
|
|
27
|
-
db_name: str = "ScrubyDB",
|
|
28
29
|
) -> None:
|
|
29
30
|
self.__class_model = class_model
|
|
30
|
-
self.__db_name = db_name
|
|
31
|
-
|
|
32
|
-
@property
|
|
33
|
-
def db_name(self) -> str:
|
|
34
|
-
"""Get database name."""
|
|
35
|
-
return self.__db_name
|
|
36
31
|
|
|
37
32
|
async def get_leaf_path(self, key: str) -> Path:
|
|
38
33
|
"""Get the path to the database cell by key.
|
|
@@ -46,7 +41,7 @@ class Scruby(Generic[T]): # noqa: UP046
|
|
|
46
41
|
separated_md5: str = "/".join(list(key_md5))
|
|
47
42
|
# The path of the branch to the database.
|
|
48
43
|
branch_path: Path = Path(
|
|
49
|
-
*(
|
|
44
|
+
*(constants.DB_ROOT, self.__class_model.__name__, separated_md5),
|
|
50
45
|
)
|
|
51
46
|
# If the branch does not exist, need to create it.
|
|
52
47
|
if not await branch_path.exists():
|
|
@@ -135,8 +130,10 @@ class Scruby(Generic[T]): # noqa: UP046
|
|
|
135
130
|
async def napalm(self) -> None:
|
|
136
131
|
"""Asynchronous method for full database deletion (Arg: db_name).
|
|
137
132
|
|
|
133
|
+
The main purpose is tests.
|
|
134
|
+
|
|
138
135
|
Warning:
|
|
139
136
|
- `Be careful, this will remove all keys.`
|
|
140
137
|
"""
|
|
141
|
-
await to_thread.run_sync(rmtree,
|
|
138
|
+
await to_thread.run_sync(rmtree, constants.DB_ROOT)
|
|
142
139
|
return
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.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
|
|
@@ -97,31 +97,27 @@ uv add scruby
|
|
|
97
97
|
import anyio
|
|
98
98
|
import datetime
|
|
99
99
|
from pydantic import BaseModel
|
|
100
|
-
from scruby import Scruby
|
|
100
|
+
from scruby import Scruby, constants
|
|
101
101
|
|
|
102
|
+
constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
"""
|
|
105
|
-
|
|
106
|
-
class User(BaseModel):
|
|
107
|
-
"""User model."""
|
|
108
|
-
|
|
109
|
-
first_name: str
|
|
110
|
-
last_name: str
|
|
111
|
-
birthday: datetime.datetime
|
|
112
|
-
email: str
|
|
113
|
-
phone: str
|
|
104
|
+
class User(BaseModel):
|
|
105
|
+
"""Model of User."""
|
|
114
106
|
|
|
107
|
+
first_name: str
|
|
108
|
+
last_name: str
|
|
109
|
+
birthday: datetime.datetime
|
|
110
|
+
email: str
|
|
111
|
+
phone: str
|
|
115
112
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)
|
|
113
|
+
async def main() -> None:
|
|
114
|
+
"""Example."""
|
|
115
|
+
db = Scruby(User)
|
|
120
116
|
|
|
121
117
|
user = User(
|
|
122
118
|
first_name="John",
|
|
123
119
|
last_name="Smith",
|
|
124
|
-
birthday=datetime.datetime(1970, 1, 1),
|
|
120
|
+
birthday=datetime.datetime(1970, 1, 1),
|
|
125
121
|
email="John_Smith@gmail.com",
|
|
126
122
|
phone="+447986123456",
|
|
127
123
|
)
|
|
@@ -139,6 +135,7 @@ async def main() -> None:
|
|
|
139
135
|
await db.delete_key("key missing") # => KeyError
|
|
140
136
|
|
|
141
137
|
# Full database deletion.
|
|
138
|
+
# Hint: The main purpose is tests.
|
|
142
139
|
await db.napalm()
|
|
143
140
|
await db.napalm() # => FileNotFoundError
|
|
144
141
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
scruby/__init__.py,sha256=LnHBN1pIOtT89baSQoknQwYI1cy-hmN1Lo0k8o1Ms48,659
|
|
2
|
+
scruby/constants.py,sha256=kwF0FIbeChBxsNxOCQhMsDEn1lakD7MIQKJ-PHYeSAo,328
|
|
3
|
+
scruby/db.py,sha256=iG1D4-ncVrVysp7OXH-eZksnNacjNna4_8nUbMkWnSE,4409
|
|
4
|
+
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
scruby-0.5.0.dist-info/METADATA,sha256=6V1NV3KWNRsc2Gb2cZbBQ4VsLYbIDMWkCiM9CjkJyxo,6509
|
|
6
|
+
scruby-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
scruby-0.5.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
scruby-0.5.0.dist-info/RECORD,,
|
scruby-0.4.0.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
scruby/__init__.py,sha256=TCxUjBI5A0KZcwvfmgaBVl8ScuzzOVvALl_T4iqSR9c,603
|
|
2
|
-
scruby/db.py,sha256=86e-U3IvNADoYhHv4PHGikqnH4KWVJEpu3d7oGuUc3s,4600
|
|
3
|
-
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
scruby-0.4.0.dist-info/METADATA,sha256=Oi3khca39iX9qdOuF-SEMtT6rkbESwDS8Wy3Zhjo8-o,6512
|
|
5
|
-
scruby-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
-
scruby-0.4.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
7
|
-
scruby-0.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|