scruby 2.4.0__py3-none-any.whl → 2.4.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.
scruby/cache.py CHANGED
@@ -12,7 +12,6 @@ from typing import Any, ClassVar, Literal, Never, assert_never, final
12
12
  import orjson
13
13
 
14
14
  from scruby.config import ScrubyConfig
15
- from scruby.meta import Metadata
16
15
 
17
16
 
18
17
  @final
@@ -59,20 +58,18 @@ class DocCache:
59
58
  @classmethod
60
59
  def load_cache(cls, subclasses: list[Any]) -> None:
61
60
  """Load all documents from the database into the cache."""
62
- db_root: Path = Path(ScrubyConfig.db_root)
63
61
  HASH_REDUCE_LEFT: Literal[7, 6, 5, 0] = ScrubyConfig.HASH_REDUCE_LEFT
62
+
63
+ if HASH_REDUCE_LEFT == 0:
64
+ return
65
+
66
+ db_root: Path = Path(ScrubyConfig.db_root)
64
67
  MAX_NUMBER_BRANCH: Literal[16, 256, 4096, 4294967296] = ScrubyConfig.MAX_NUMBER_BRANCH
65
68
  branch_numbers: range = range(MAX_NUMBER_BRANCH)
66
69
 
67
70
  for subclass in subclasses:
68
71
  collection_name: str = subclass.__name__
69
72
 
70
- # Create metadata for the collection if it is missing
71
- Metadata.create(collection_name)
72
-
73
- if HASH_REDUCE_LEFT == 0:
74
- continue
75
-
76
73
  # Create a cache structure for the collection
77
74
  cls.create_structure(collection_name)
78
75
 
scruby/db.py CHANGED
@@ -20,7 +20,7 @@ from xloft import NamedTuple
20
20
  from scruby import mixins
21
21
  from scruby.cache import DocCache
22
22
  from scruby.config import ScrubyConfig
23
- from scruby.meta import Meta
23
+ from scruby.meta import Meta, Metadata
24
24
  from scruby.migration import Migration
25
25
  from scruby.model import ScrubyModel
26
26
 
@@ -210,4 +210,14 @@ class Scruby(
210
210
  ScrubyConfig.init_params()
211
211
  ScrubyConfig.check_hash_reduce_left()
212
212
  Migration.run(db_root, subclasses)
213
+
214
+ max_number_branch = ScrubyConfig.MAX_NUMBER_BRANCH
215
+ for subclass in subclasses:
216
+ Metadata.create(
217
+ db_root,
218
+ hash_reduce_left,
219
+ max_number_branch,
220
+ subclass.__name__,
221
+ )
222
+
213
223
  DocCache.load_cache(subclasses)
scruby/meta.py CHANGED
@@ -14,8 +14,6 @@ from pathlib import Path
14
14
 
15
15
  from pydantic import BaseModel
16
16
 
17
- from scruby.config import ScrubyConfig
18
-
19
17
 
20
18
  class Meta(BaseModel):
21
19
  """Structure of metadata for collection."""
@@ -30,17 +28,15 @@ class Metadata:
30
28
  """Metadata management."""
31
29
 
32
30
  @staticmethod
33
- def create(collection_name: str) -> None:
34
- """Create metadata for collection.
35
-
36
- Args:
37
- collection_name (str): Collection name.
38
-
39
- Returns:
40
- None.
41
- """
31
+ def create(
32
+ db_root: Path | str,
33
+ hash_reduce_left: int,
34
+ max_number_branch: int,
35
+ collection_name: str,
36
+ ) -> None:
37
+ """Create metadata for collections."""
42
38
  meta_dir_path = Path(
43
- ScrubyConfig.db_root,
39
+ db_root,
44
40
  collection_name,
45
41
  "meta",
46
42
  )
@@ -48,8 +44,8 @@ class Metadata:
48
44
  meta_dir_path.mkdir(parents=True)
49
45
  meta = Meta(
50
46
  collection_name=collection_name,
51
- hash_reduce_left=ScrubyConfig.HASH_REDUCE_LEFT,
52
- max_number_branch=ScrubyConfig.MAX_NUMBER_BRANCH,
47
+ hash_reduce_left=hash_reduce_left,
48
+ max_number_branch=max_number_branch,
53
49
  counter_documents=0,
54
50
  )
55
51
  meta_json = meta.model_dump_json()
scruby/migration.py CHANGED
@@ -19,6 +19,8 @@ class Migration:
19
19
  """Run migration."""
20
20
  # Delete collections whose models have been deleted
21
21
  cls.delete_orphan_collections(db_root, subclasses)
22
+ # Add collection directories if they are missing
23
+ cls.add_collection_directories(db_root, subclasses)
22
24
 
23
25
  @staticmethod
24
26
  def delete_orphan_collections(db_root: Path | str, subclasses: list[Any]) -> None:
@@ -31,3 +33,12 @@ class Migration:
31
33
  if collection_name not in model_collection_list:
32
34
  target_directory = Path(db_root, collection_name)
33
35
  rmtree(target_directory)
36
+
37
+ @staticmethod
38
+ def add_collection_directories(db_root: Path | str, subclasses: list[Any]) -> None:
39
+ """Add collection directories if they are missing."""
40
+ for subclass in subclasses:
41
+ collection_name = subclass.__name__
42
+ coll_dir_path = Path(db_root, collection_name)
43
+ if not coll_dir_path.exists():
44
+ coll_dir_path.mkdir(parents=True)
@@ -47,14 +47,24 @@ class Collection:
47
47
  Returns:
48
48
  None.
49
49
  """
50
+ db_root = ScrubyConfig.db_root
51
+ hash_reduce_left = ScrubyConfig.HASH_REDUCE_LEFT
52
+ max_number_branch = ScrubyConfig.MAX_NUMBER_BRANCH
53
+
50
54
  # Delete collection on file system
51
- target_directory = f"{ScrubyConfig.db_root}/{collection_name}"
55
+ target_directory = f"{db_root}/{collection_name}"
52
56
  rmtree(target_directory)
53
- # Create collection and metadata
54
- Metadata.create(collection_name)
57
+
58
+ # Create a directory for the collection and add metadata
59
+ Metadata.create(
60
+ db_root,
61
+ hash_reduce_left,
62
+ max_number_branch,
63
+ collection_name,
64
+ )
55
65
 
56
66
  # Clear collection in cache
57
- if ScrubyConfig.HASH_REDUCE_LEFT != 0:
67
+ if hash_reduce_left != 0:
58
68
  del DocCache.cache[collection_name]
59
69
  DocCache.create_structure(collection_name)
60
70
  return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 2.4.0
3
+ Version: 2.4.2
4
4
  Summary: Asynchronous library for building and managing a hybrid database, by scheme of key-value.
5
5
  Project-URL: Bug Tracker, https://github.com/kebasyaty/scruby/issues
6
6
  Project-URL: Changelog, https://github.com/kebasyaty/scruby/blob/v2/CHANGELOG.md
@@ -43,7 +43,7 @@ Description-Content-Type: text/markdown
43
43
  <img
44
44
  width="100%"
45
45
  alt="Logo"
46
- src="https://raw.githubusercontent.com/kebasyaty/scruby/v2/assets/logo.jpg">
46
+ src="https://raw.githubusercontent.com/kebasyaty/scruby/v2/assets/logo.png">
47
47
  </a>
48
48
  </p>
49
49
  <p>
@@ -164,7 +164,7 @@ async def main() -> None:
164
164
  # Activate database.
165
165
  Scruby.run()
166
166
 
167
- # Get/Create a User collection
167
+ # Get access to the collection
168
168
  user_coll = Scruby(User)
169
169
 
170
170
  # Create user
@@ -247,7 +247,7 @@ async def main() -> None:
247
247
  # Activate database.
248
248
  Scruby.run()
249
249
 
250
- # Get/Create a Phone collection
250
+ # Get access to the collection
251
251
  phone_coll = Scruby(Phone)
252
252
 
253
253
  # Create phone
@@ -324,7 +324,7 @@ async def main() -> None:
324
324
  # Activate database.
325
325
  Scruby.run()
326
326
 
327
- # Get/Create a Car collection
327
+ # Get access to the collection
328
328
  car_coll = Scruby(Car)
329
329
 
330
330
  # Create cars
@@ -1,24 +1,24 @@
1
1
  scruby/__init__.py,sha256=deNLNpHBxrXFFRtIp6JakcyeaOuedFN1MiPTsXKLAis,1368
2
2
  scruby/aggregation.py,sha256=NBFxQqyRqUG2KIuD9fbl4uzSHJWTaskjiZ1YNBa-Zbo,3575
3
- scruby/cache.py,sha256=j_uRBF72p7kzUK6GMHIIqb8nM2RneCod45dbbI1KTjQ,4018
3
+ scruby/cache.py,sha256=DRcTdQbh1DhTQDGK5oC_mZrjcQg6g06vJ1e61RfNX94,3864
4
4
  scruby/config.py,sha256=oyBEOzmKy9vka23ZDvP8Jqu-HMYn8HCmJ0j2TfOs-0w,5127
5
- scruby/db.py,sha256=ZhPoW0O1SYPhTqFTKc0GOQZjn6Lii3HOUHcfRPlP_eM,7189
5
+ scruby/db.py,sha256=Kmb1Zo7IVfajjeHLCgj4clm0U2iRTggu5oiCXnnqDzk,7468
6
6
  scruby/errors.py,sha256=lTWiHzyO5Es9Nkf7quODJjONGn6ifcL95qlpA4epQQM,1386
7
- scruby/meta.py,sha256=dfr8q3TWhVcEl-lZuH5yd9rbO9vAPBhXBO3VYCNcOWo,1283
8
- scruby/migration.py,sha256=SkbiSrSIqspQZTEXvg-yqWz5CLBvtnuwfl8G7flOS0Q,1083
7
+ scruby/meta.py,sha256=W6ikKkGItR63ZAY1HclCcUqs8JdVkeoubJt0wkU5vEM,1200
8
+ scruby/migration.py,sha256=ZMKf64OaTkmMXgkFrz-XQlPrb5ghVps0N6lFrXSYQYA,1605
9
9
  scruby/model.py,sha256=1infUd1G-zxj5Z93mNOp1Wi2anD6TKDgu5Y0KEVcH2k,292
10
10
  scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  scruby/utils.py,sha256=l-UNz_DEuYEx6vS8ExgFGzbueQ6RwencClZQUr3VReo,2437
12
12
  scruby/mixins/__init__.py,sha256=nT79e80zXliuTGhR9CFosI2-3PQUCKwXbR7wPiFwgrU,669
13
- scruby/mixins/collection.py,sha256=lnwViHrJFrammQhJFGX_zicdr008-6GNcRI09JpXR-c,1759
13
+ scruby/mixins/collection.py,sha256=QAvsRBYQvSnmBF1zDPA0NoXRl-PS0Qdy97MRfg1O6SU,2019
14
14
  scruby/mixins/count.py,sha256=CGpyOpsG25uC5utI2ByNxq2iTbJocj6w5tXrC1_cP40,2561
15
15
  scruby/mixins/custom_task.py,sha256=DIry4gBlTdaqZqymar-RrHSdhEiC2tn2pl9jmbk56zw,1547
16
16
  scruby/mixins/delete.py,sha256=InKVIud_ZYx9-CchUz_IygQDXMynNi4jQ0HKYeHC_R8,4328
17
17
  scruby/mixins/find.py,sha256=oEZRE6RqIBdwvNr8iSYyod8hI6ibi_egJP0pyXmJiss,9169
18
18
  scruby/mixins/keys.py,sha256=MvBy_8fQGROaQATK2qse2V8wR-xodPQG0KKZ2PK_t9U,10790
19
19
  scruby/mixins/update.py,sha256=TyxvxB-gNijlfzTmhwrq0ydvu0C3R-RihW5h5tJ96bM,4964
20
- scruby-2.4.0.dist-info/METADATA,sha256=p0EangsFZxQS9z8t3rOiDHYK6Umik7p4abH5z9UlW64,13431
21
- scruby-2.4.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
22
- scruby-2.4.0.dist-info/licenses/GPL-3.0-LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
23
- scruby-2.4.0.dist-info/licenses/MIT-LICENSE,sha256=mS0Wz0yGNB63gEcWEnuIb_lldDYV0sjRaO-o_GL6CWE,1074
24
- scruby-2.4.0.dist-info/RECORD,,
20
+ scruby-2.4.2.dist-info/METADATA,sha256=1ch9wQHuYPAF52xP8lRxnRh66vxLm-JjdXU7nfhfdTw,13431
21
+ scruby-2.4.2.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
22
+ scruby-2.4.2.dist-info/licenses/GPL-3.0-LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
23
+ scruby-2.4.2.dist-info/licenses/MIT-LICENSE,sha256=mS0Wz0yGNB63gEcWEnuIb_lldDYV0sjRaO-o_GL6CWE,1074
24
+ scruby-2.4.2.dist-info/RECORD,,
File without changes