kisa-utils 0.37.16__py3-none-any.whl → 0.37.18__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.
- kisa_utils/db.py +59 -0
- kisa_utils/functionUtils.py +6 -6
- kisa_utils/structures/utils.py +14 -4
- {kisa_utils-0.37.16.dist-info → kisa_utils-0.37.18.dist-info}/METADATA +1 -1
- {kisa_utils-0.37.16.dist-info → kisa_utils-0.37.18.dist-info}/RECORD +7 -7
- {kisa_utils-0.37.16.dist-info → kisa_utils-0.37.18.dist-info}/WHEEL +0 -0
- {kisa_utils-0.37.16.dist-info → kisa_utils-0.37.18.dist-info}/top_level.txt +0 -0
kisa_utils/db.py
CHANGED
|
@@ -11,6 +11,9 @@ from threading import get_native_id as getCurrentThreadId, Lock
|
|
|
11
11
|
from . import storage
|
|
12
12
|
from . import codes
|
|
13
13
|
from .response import Error, Ok, Response
|
|
14
|
+
from .functionUtils import enforceRequirements, Definition
|
|
15
|
+
from .structures.utils import Value
|
|
16
|
+
from . import structures
|
|
14
17
|
|
|
15
18
|
if sqlite3.sqlite_version_info[1]<38:
|
|
16
19
|
sys.exit(f'we need sqlite3 v3.38.0+ to run this program. current version::{sqlite3.sqlite_version}')
|
|
@@ -1171,6 +1174,62 @@ def transaction(*dbArgs, **dbKwargs) -> dict|Response:
|
|
|
1171
1174
|
return wrapper
|
|
1172
1175
|
return handler
|
|
1173
1176
|
|
|
1177
|
+
class Column:
|
|
1178
|
+
@enforceRequirements
|
|
1179
|
+
def __init__(
|
|
1180
|
+
self,
|
|
1181
|
+
name: Value(str, lambda n: Ok() if n and ' ' not in n and not n[0].isdigit() else Error('invalid column name given')),
|
|
1182
|
+
dataType: type, # int|float|bytes|list|dict|tuple,
|
|
1183
|
+
# bytes=blob, list|dict|tuple=JSON
|
|
1184
|
+
/,
|
|
1185
|
+
*,
|
|
1186
|
+
validator: Value|None = None, # must take 1 argument and return a
|
|
1187
|
+
# kisa_utils.response.Response object
|
|
1188
|
+
required:bool = False,
|
|
1189
|
+
maxSize:int = -1, # -1=unlimited. for ;
|
|
1190
|
+
# strings,JSON:list|tuple|dict,bytes: maxSize=`len`
|
|
1191
|
+
# int,float: maxSize=maxValue
|
|
1192
|
+
unique:bool = False,
|
|
1193
|
+
isPrimaryKey:bool = False,
|
|
1194
|
+
trackChanges: bool = False, # if set to True, all changes/updates
|
|
1195
|
+
# along with their timestamps will be logged
|
|
1196
|
+
# all changes will be stored in a special
|
|
1197
|
+
# table in the database. the very first insert
|
|
1198
|
+
# will trigger a log as well if trackChanges is
|
|
1199
|
+
# set to `True`
|
|
1200
|
+
# z:Callable|None = None
|
|
1201
|
+
) -> None:
|
|
1202
|
+
'''
|
|
1203
|
+
create a column definition/instance
|
|
1204
|
+
'''
|
|
1205
|
+
...
|
|
1206
|
+
|
|
1207
|
+
class Table:
|
|
1208
|
+
@enforceRequirements
|
|
1209
|
+
def __init__(
|
|
1210
|
+
self,
|
|
1211
|
+
name: Value(str, lambda n: Ok() if (n and ' ' not in n and not n[0].isdigit()) else Error('invalid column name given')),
|
|
1212
|
+
/,
|
|
1213
|
+
*,
|
|
1214
|
+
trackChanges: bool = False, # if set to True, all changes/updates
|
|
1215
|
+
# along with their timestamps will be logged
|
|
1216
|
+
# all changes will be stored in a special
|
|
1217
|
+
# table in the database. the very first insert
|
|
1218
|
+
# will trigger a log as well if trackChanges is
|
|
1219
|
+
# set to `True`
|
|
1220
|
+
|
|
1221
|
+
# onInsert:Callable|None=None,
|
|
1222
|
+
# onDelete:Callable|None=None,
|
|
1223
|
+
# onUpdate:Callable|None=None,
|
|
1224
|
+
) -> None:
|
|
1225
|
+
'''
|
|
1226
|
+
create a table definition
|
|
1227
|
+
'''
|
|
1228
|
+
pass
|
|
1229
|
+
|
|
1230
|
+
# ------------------------------------------------------------------------------
|
|
1174
1231
|
if __name__=='__main__':
|
|
1232
|
+
# Column('ab', int)
|
|
1233
|
+
|
|
1175
1234
|
with Api('/tmp/bukman/database.db2') as handle:
|
|
1176
1235
|
print(handle.fetch('keys',['*'],'',[]))
|
kisa_utils/functionUtils.py
CHANGED
|
@@ -6,11 +6,14 @@ from kisa_utils.response import Response, Ok, Error
|
|
|
6
6
|
from kisa_utils.storage import Path
|
|
7
7
|
from kisa_utils.structures.validator import Value, validateWithResponse
|
|
8
8
|
import copy
|
|
9
|
-
from typing import Any, get_args, Callable
|
|
9
|
+
from typing import Any, get_args, Callable, Generic, ParamSpec, TypeVar
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
P = ParamSpec('P')
|
|
12
|
+
T = TypeVar('T')
|
|
13
|
+
|
|
14
|
+
class Definition(Generic[T]):
|
|
12
15
|
@staticmethod
|
|
13
|
-
def __class_getitem__(structure:
|
|
16
|
+
def __class_getitem__(structure:type[T]) -> Any:
|
|
14
17
|
return structure
|
|
15
18
|
|
|
16
19
|
def private(func:Callable) -> Callable:
|
|
@@ -60,9 +63,6 @@ def protected(func:Callable) -> Callable:
|
|
|
60
63
|
return wrapper
|
|
61
64
|
|
|
62
65
|
# ------------------------------------------------------------------------------
|
|
63
|
-
from typing import ParamSpec, TypeVar
|
|
64
|
-
P = ParamSpec('P')
|
|
65
|
-
T = TypeVar('T')
|
|
66
66
|
|
|
67
67
|
def enforceRequirements(func:Callable[P, T]) -> Callable[P, T]:
|
|
68
68
|
'''
|
kisa_utils/structures/utils.py
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import typing
|
|
3
|
-
from typing import Any, Callable, get_origin
|
|
3
|
+
from typing import Any, Callable, get_origin, Generic, overload
|
|
4
4
|
from types import UnionType
|
|
5
5
|
from kisa_utils.response import Response
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
from typing import ParamSpec, TypeVar, Type
|
|
8
|
+
P = ParamSpec('P')
|
|
9
|
+
T = TypeVar('T')
|
|
10
|
+
|
|
11
|
+
class Value(Generic[T]):
|
|
12
|
+
@overload
|
|
13
|
+
def __init__(self, valueType:Type[T], validator:Callable[[T], Response],/) -> None: ...
|
|
14
|
+
|
|
15
|
+
@overload
|
|
16
|
+
def __init__(self, valueType:Type[T] | TypeVar, validator:Callable[[T], Response],/) -> None: ...
|
|
17
|
+
|
|
18
|
+
def __init__(self, valueType, validator, /) -> None:
|
|
9
19
|
'''
|
|
10
20
|
create a value definition to be used by `kisa_utils.structures.validator.validate`
|
|
11
21
|
|
|
@@ -70,4 +80,4 @@ class Value:
|
|
|
70
80
|
return _type
|
|
71
81
|
|
|
72
82
|
def __str__(self) -> str: return self.__name__
|
|
73
|
-
def __repr__(self) -> str: return self.__name__
|
|
83
|
+
def __repr__(self) -> str: return self.__name__
|
|
@@ -3,11 +3,11 @@ kisa_utils/cache.py,sha256=4Ue5G3QhHSQAmIfQKYgWKWjNL4rA4wLLd_RdBLb2ABY,7345
|
|
|
3
3
|
kisa_utils/codes.py,sha256=PV_S53Skggf4XetOdYoIKtEmM8cpN5wZwUlxje70WZY,904
|
|
4
4
|
kisa_utils/config.py,sha256=NfluzGKTh66qfNtC-Ae0zNb1XzMTgU2Me9Vi82R9c1E,2285
|
|
5
5
|
kisa_utils/dates.py,sha256=kcNqoY_iguG9hSzABMIBqeL3MGz3n4MRIXuW4OxRHLs,12662
|
|
6
|
-
kisa_utils/db.py,sha256=
|
|
6
|
+
kisa_utils/db.py,sha256=QH9nvwc3Lr-NyUA-47Rae-s2xeMIE6m2rNGozcpr2jg,48950
|
|
7
7
|
kisa_utils/encryption.py,sha256=nFzNpzWV_D9uSEq4FsgCnlS7FQtqWP9fvM_81rsfcLo,4218
|
|
8
8
|
kisa_utils/enqueue.py,sha256=VIliaMvw4MUdOqts0dXdZCYNxs-QrOVjIRAR3scGrRM,11786
|
|
9
9
|
kisa_utils/figures.py,sha256=pYIpQzu1OXRSsY1d98GhgPifnIRmgl-r7S32ai-Ms0c,3731
|
|
10
|
-
kisa_utils/functionUtils.py,sha256=
|
|
10
|
+
kisa_utils/functionUtils.py,sha256=I33ZeDNcQsumhgWyFWodj0D3RKkwfiUFZfCGwmAkDYo,6561
|
|
11
11
|
kisa_utils/log.py,sha256=0TYdxcIBts026RCSuVIQBcZ-CW1ES7n3M1nEIjmeLTM,2295
|
|
12
12
|
kisa_utils/queues.py,sha256=9QqPtDujw6tbWk7uUiXrsd0rVBTIkzeQw9b45l5Fo3k,6502
|
|
13
13
|
kisa_utils/remote.py,sha256=0RDrfC4RUW4m6JLziC0_EXJYqzWp38Rw8NDroJ0MuqI,2149
|
|
@@ -21,9 +21,9 @@ kisa_utils/permissions/__init__.py,sha256=q7LGl26f-MPXkLS6nxBKDotW3xdB8y7pI5S_Oo
|
|
|
21
21
|
kisa_utils/servers/__init__.py,sha256=lPqDyGTrFo0qwPZ2WA9Xtcpc5D8AIU4huqgFx1iZf68,19
|
|
22
22
|
kisa_utils/servers/flask.py,sha256=o76cJKlQ3L8EOVdHUF092qwoAZMzgttuLt0mMhtCsGI,40085
|
|
23
23
|
kisa_utils/structures/__init__.py,sha256=JBU1j3A42jQ62ALKnsS1Hav9YXcYwjDw1wQJtohXPbU,83
|
|
24
|
-
kisa_utils/structures/utils.py,sha256=
|
|
24
|
+
kisa_utils/structures/utils.py,sha256=665rXIapGwFqejizeJwy3DryeskCQOdgP25BCdLkGvk,2898
|
|
25
25
|
kisa_utils/structures/validator.py,sha256=Y4UmB4TH7N-GkK22EV1WOsPWjTeqxVWLTentl1keZD4,4053
|
|
26
|
-
kisa_utils-0.37.
|
|
27
|
-
kisa_utils-0.37.
|
|
28
|
-
kisa_utils-0.37.
|
|
29
|
-
kisa_utils-0.37.
|
|
26
|
+
kisa_utils-0.37.18.dist-info/METADATA,sha256=gTcrLt0Vr8OPx_6bCHDe_Zs0sAh2hqlriAeJg41LFGA,478
|
|
27
|
+
kisa_utils-0.37.18.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
28
|
+
kisa_utils-0.37.18.dist-info/top_level.txt,sha256=URxY4sRuqmirOxWtztpVmPoGQdksEMYO6hmYsEDGz2Y,75
|
|
29
|
+
kisa_utils-0.37.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|