kisa-utils 0.37.16__py3-none-any.whl → 0.37.17__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 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
+ # Column('ab', int)
1231
+
1232
+ # ------------------------------------------------------------------------------
1174
1233
  if __name__=='__main__':
1175
1234
  with Api('/tmp/bukman/database.db2') as handle:
1176
1235
  print(handle.fetch('keys',['*'],'',[]))
@@ -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
- class Definition:
11
+ P = ParamSpec('P')
12
+ T = TypeVar('T')
13
+
14
+ class Definition(Generic[T]):
12
15
  @staticmethod
13
- def __class_getitem__(structure:Any) -> Any:
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
  '''
@@ -1,11 +1,15 @@
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
4
4
  from types import UnionType
5
5
  from kisa_utils.response import Response
6
6
 
7
- class Value:
8
- def __init__(self, valueType:Any, validator:Callable,/) -> None:
7
+ from typing import ParamSpec, TypeVar
8
+ P = ParamSpec('P')
9
+ T = TypeVar('T')
10
+
11
+ class Value(Generic[T]):
12
+ def __init__(self, valueType:type[T], validator:Callable[[T], Response],/) -> None:
9
13
  '''
10
14
  create a value definition to be used by `kisa_utils.structures.validator.validate`
11
15
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kisa-utils
3
- Version: 0.37.16
3
+ Version: 0.37.17
4
4
  Summary: Utility functions and modules for KISA Developers
5
5
  Author: Tom Bukenya
6
6
  Author-email: glayn2bukman@gmail.com
@@ -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=tv3cvKhOu0NQ3NeykkJlhqJBFM-wQcLIxWZc8lsocCg,46485
6
+ kisa_utils/db.py,sha256=wn9IS1qvT46NOW1eUKFbMteMN_iRUftDXJa_cCP4FWE,48944
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=PlXjnmU1uJWNdISlJJ3SCgavTsgNBoebaa9dtWSFhRA,6553
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=l56NQiPVcFijpuLqt2n9ZwnVKT4XzK6oknRVallRzwQ,2573
24
+ kisa_utils/structures/utils.py,sha256=6nGEE5IJ2vM7xM4ABZZMnFnB65SuoDUWg9gK5exyk6Q,2688
25
25
  kisa_utils/structures/validator.py,sha256=Y4UmB4TH7N-GkK22EV1WOsPWjTeqxVWLTentl1keZD4,4053
26
- kisa_utils-0.37.16.dist-info/METADATA,sha256=LERWYuPWHT0mNh8bCpHawI1uS3ebvczXyMdsfdzMMVI,478
27
- kisa_utils-0.37.16.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
28
- kisa_utils-0.37.16.dist-info/top_level.txt,sha256=URxY4sRuqmirOxWtztpVmPoGQdksEMYO6hmYsEDGz2Y,75
29
- kisa_utils-0.37.16.dist-info/RECORD,,
26
+ kisa_utils-0.37.17.dist-info/METADATA,sha256=PKNHUXovfxBqBfZv0H8UjM10QomhAhjW3ghEO0TpSbE,478
27
+ kisa_utils-0.37.17.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
28
+ kisa_utils-0.37.17.dist-info/top_level.txt,sha256=URxY4sRuqmirOxWtztpVmPoGQdksEMYO6hmYsEDGz2Y,75
29
+ kisa_utils-0.37.17.dist-info/RECORD,,