scruby 0.9.3__py3-none-any.whl → 0.27.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/__init__.py +37 -29
- scruby/aggregation.py +152 -0
- scruby/db.py +213 -301
- scruby/errors.py +45 -0
- scruby/mixins/__init__.py +25 -0
- scruby/mixins/collection.py +50 -0
- scruby/mixins/count.py +62 -0
- scruby/mixins/custom_task.py +75 -0
- scruby/mixins/delete.py +96 -0
- scruby/mixins/docs.py +168 -0
- scruby/mixins/find.py +149 -0
- scruby/mixins/update.py +99 -0
- scruby/settings.py +44 -0
- {scruby-0.9.3.dist-info → scruby-0.27.2.dist-info}/METADATA +138 -112
- scruby-0.27.2.dist-info/RECORD +18 -0
- {scruby-0.9.3.dist-info → scruby-0.27.2.dist-info}/WHEEL +1 -1
- {scruby-0.9.3.dist-info → scruby-0.27.2.dist-info}/licenses/LICENSE +21 -21
- scruby/constants.py +0 -31
- scruby-0.9.3.dist-info/RECORD +0 -8
scruby/__init__.py
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
#
|
|
2
|
+
# .|'''| '||
|
|
3
|
+
# || ||
|
|
4
|
+
# `|'''|, .|'', '||''| '|| ||` ||''|, '|| ||`
|
|
5
|
+
# . || || || || || || || `|..||
|
|
6
|
+
# |...|' `|..' .||. `|..'|. .||..|' ||
|
|
7
|
+
# , |'
|
|
8
|
+
# ''
|
|
9
|
+
#
|
|
10
|
+
# Copyright (c) 2025 Gennady Kostyunin
|
|
11
|
+
# SPDX-License-Identifier: MIT
|
|
12
|
+
#
|
|
13
|
+
"""Asynchronous library for building and managing a hybrid database, by scheme of key-value.
|
|
14
|
+
|
|
15
|
+
The library uses fractal-tree addressing and
|
|
16
|
+
the search for documents based on the effect of a quantum loop.
|
|
17
|
+
|
|
18
|
+
The database consists of collections.
|
|
19
|
+
The maximum size of the one collection is 16**8=4294967296 branches,
|
|
20
|
+
each branch can store one or more keys.
|
|
21
|
+
|
|
22
|
+
The value of any key in collection can be obtained in 8 steps,
|
|
23
|
+
thereby achieving high performance.
|
|
24
|
+
|
|
25
|
+
The effectiveness of the search for documents based on a quantum loop,
|
|
26
|
+
requires a large number of processor threads.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
__all__ = (
|
|
32
|
+
"settings",
|
|
33
|
+
"Scruby",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
from scruby import settings
|
|
37
|
+
from scruby.db import Scruby
|
scruby/aggregation.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Scruby - Asynchronous library for building and managing a hybrid database, by scheme of key-value.
|
|
2
|
+
# Copyright (c) 2025 Gennady Kostyunin
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
#
|
|
5
|
+
"""Aggregation classes."""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
__all__ = (
|
|
10
|
+
"Average",
|
|
11
|
+
"Counter",
|
|
12
|
+
"Max",
|
|
13
|
+
"Min",
|
|
14
|
+
"Sum",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from decimal import ROUND_HALF_EVEN, Decimal
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Average:
|
|
22
|
+
"""Aggregation class for calculating the average value.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
precision: The accuracy of rounding. `By default = .00`
|
|
26
|
+
rounding: Rounding mode. `By default = ROUND_HALF_EVEN`
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__( # noqa: D107
|
|
30
|
+
self,
|
|
31
|
+
precision: str = ".00",
|
|
32
|
+
rounding: str = ROUND_HALF_EVEN,
|
|
33
|
+
) -> None:
|
|
34
|
+
self.value = Decimal()
|
|
35
|
+
self.counter = 0
|
|
36
|
+
self.precision = precision
|
|
37
|
+
self.rounding = rounding
|
|
38
|
+
|
|
39
|
+
def set(self, number: int | float) -> None:
|
|
40
|
+
"""Add value.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
number: Current value (int | float).
|
|
44
|
+
"""
|
|
45
|
+
self.value += Decimal(str(number))
|
|
46
|
+
self.counter += 1
|
|
47
|
+
|
|
48
|
+
def get(self) -> Decimal:
|
|
49
|
+
"""Get arithmetic average value.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
Number (Decimal) - Average value.
|
|
53
|
+
"""
|
|
54
|
+
return (self.value / Decimal(str(self.counter))).quantize(
|
|
55
|
+
exp=Decimal(self.precision),
|
|
56
|
+
rounding=self.rounding,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Counter:
|
|
61
|
+
"""Aggregation class for calculating the number of documents.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
limit: The maximum counter value.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(self, limit: int = 1000) -> None: # noqa: D107
|
|
68
|
+
self.limit = limit
|
|
69
|
+
self.counter = 0
|
|
70
|
+
|
|
71
|
+
def check(self) -> bool:
|
|
72
|
+
"""Check the condition of the counter.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
Boolean value. If `True`, the maximum value is achieved.
|
|
76
|
+
"""
|
|
77
|
+
return self.counter >= self.limit
|
|
78
|
+
|
|
79
|
+
def next(self) -> None:
|
|
80
|
+
"""Increment the counter on one."""
|
|
81
|
+
self.counter += 1
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class Max:
|
|
85
|
+
"""Aggregation class for calculating the maximum value."""
|
|
86
|
+
|
|
87
|
+
def __init__(self) -> None: # noqa: D107
|
|
88
|
+
self.value: Any = 0
|
|
89
|
+
|
|
90
|
+
def set(self, number: int | float) -> None:
|
|
91
|
+
"""Add value.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
number: Current value.
|
|
95
|
+
"""
|
|
96
|
+
if number > self.value:
|
|
97
|
+
self.value = number
|
|
98
|
+
|
|
99
|
+
def get(self) -> Any:
|
|
100
|
+
"""Get maximum value.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
Number (int|float) - Maximum value.
|
|
104
|
+
"""
|
|
105
|
+
return self.value
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class Min:
|
|
109
|
+
"""Aggregation class for calculating the minimum value."""
|
|
110
|
+
|
|
111
|
+
def __init__(self) -> None: # noqa: D107
|
|
112
|
+
self.value: Any = 0
|
|
113
|
+
|
|
114
|
+
def set(self, number: int | float) -> None:
|
|
115
|
+
"""Add value.
|
|
116
|
+
|
|
117
|
+
Args:
|
|
118
|
+
number: Current value.
|
|
119
|
+
"""
|
|
120
|
+
if self.value == 0 or number < self.value:
|
|
121
|
+
self.value = number
|
|
122
|
+
|
|
123
|
+
def get(self) -> Any:
|
|
124
|
+
"""Get minimum value.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
Number (int|float) - Minimum value.
|
|
128
|
+
"""
|
|
129
|
+
return self.value
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class Sum:
|
|
133
|
+
"""Aggregation class for calculating sum of values."""
|
|
134
|
+
|
|
135
|
+
def __init__(self) -> None: # noqa: D107
|
|
136
|
+
self.value = Decimal()
|
|
137
|
+
|
|
138
|
+
def set(self, number: int | float) -> None:
|
|
139
|
+
"""Add value.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
number: Current value.
|
|
143
|
+
"""
|
|
144
|
+
self.value += Decimal(str(number))
|
|
145
|
+
|
|
146
|
+
def get(self) -> Decimal:
|
|
147
|
+
"""Get sum of values.
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
Number (int|float) - Sum of values.
|
|
151
|
+
"""
|
|
152
|
+
return self.value
|