database-wrapper 0.1.33__py3-none-any.whl → 0.1.37__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.
- database_wrapper/__init__.py +2 -3
- database_wrapper/common.py +14 -0
- database_wrapper/config.py +3 -3
- database_wrapper/db_data_model.py +50 -3
- database_wrapper/db_wrapper.py +71 -296
- database_wrapper/db_wrapper_async.py +69 -295
- database_wrapper/db_wrapper_mixin.py +308 -0
- database_wrapper/utils/dataclass_addons.py +3 -3
- {database_wrapper-0.1.33.dist-info → database_wrapper-0.1.37.dist-info}/METADATA +5 -5
- database_wrapper-0.1.37.dist-info/RECORD +16 -0
- {database_wrapper-0.1.33.dist-info → database_wrapper-0.1.37.dist-info}/WHEEL +1 -1
- database_wrapper/db_wrapper_interface.py +0 -434
- database_wrapper-0.1.33.dist-info/RECORD +0 -15
- {database_wrapper-0.1.33.dist-info → database_wrapper-0.1.37.dist-info}/top_level.txt +0 -0
|
@@ -1,434 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
|
|
3
|
-
from abc import ABC, abstractmethod
|
|
4
|
-
from typing import TypeVar, Any, overload
|
|
5
|
-
|
|
6
|
-
from .db_backend import DatabaseBackend
|
|
7
|
-
from .db_data_model import DBDataModel
|
|
8
|
-
|
|
9
|
-
OrderByItem = list[tuple[str, str | None]]
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class NoParam:
|
|
13
|
-
pass
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# Bound T to DBDataModel
|
|
17
|
-
T = TypeVar("T", bound=DBDataModel)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class DBWrapperInterface(ABC):
|
|
21
|
-
"""
|
|
22
|
-
Database wrapper class interface.
|
|
23
|
-
|
|
24
|
-
This class defines the interface for the database wrapper classes.
|
|
25
|
-
|
|
26
|
-
:property db: Database backend object.
|
|
27
|
-
:property dbConn: Database connection object.
|
|
28
|
-
:property logger: Logger object
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
###########################
|
|
32
|
-
### Instance properties ###
|
|
33
|
-
###########################
|
|
34
|
-
|
|
35
|
-
# Db backend
|
|
36
|
-
db: DatabaseBackend
|
|
37
|
-
"""Database backend object."""
|
|
38
|
-
|
|
39
|
-
dbConn: Any
|
|
40
|
-
"""Database connection object."""
|
|
41
|
-
|
|
42
|
-
logger: logging.Logger | None
|
|
43
|
-
"""Logger object"""
|
|
44
|
-
|
|
45
|
-
#######################
|
|
46
|
-
### Class lifecycle ###
|
|
47
|
-
#######################
|
|
48
|
-
|
|
49
|
-
@abstractmethod
|
|
50
|
-
def __init__(
|
|
51
|
-
self,
|
|
52
|
-
db: DatabaseBackend,
|
|
53
|
-
dbConn: Any = None,
|
|
54
|
-
logger: logging.Logger | None = None,
|
|
55
|
-
):
|
|
56
|
-
"""
|
|
57
|
-
Initializes a new instance of the DBWrapper class.
|
|
58
|
-
|
|
59
|
-
Args:
|
|
60
|
-
db (DatabaseBackend): The DatabaseBackend object.
|
|
61
|
-
logger (logging.Logger, optional): The logger object. Defaults to None.
|
|
62
|
-
"""
|
|
63
|
-
...
|
|
64
|
-
|
|
65
|
-
@abstractmethod
|
|
66
|
-
def __del__(self):
|
|
67
|
-
"""
|
|
68
|
-
Deallocates the instance of the DBWrapper class.
|
|
69
|
-
"""
|
|
70
|
-
...
|
|
71
|
-
|
|
72
|
-
@abstractmethod
|
|
73
|
-
def close(self) -> Any:
|
|
74
|
-
"""
|
|
75
|
-
Close resources. Usually you should not close connections here, just remove references.
|
|
76
|
-
"""
|
|
77
|
-
...
|
|
78
|
-
|
|
79
|
-
######################
|
|
80
|
-
### Helper methods ###
|
|
81
|
-
######################
|
|
82
|
-
|
|
83
|
-
@abstractmethod
|
|
84
|
-
def makeIdentifier(self, schema: str | None, name: str) -> Any:
|
|
85
|
-
"""
|
|
86
|
-
Creates a SQL identifier object from the given name.
|
|
87
|
-
|
|
88
|
-
Args:
|
|
89
|
-
schema (str | None): The schema to create the identifier from.
|
|
90
|
-
name (str): The name to create the identifier from.
|
|
91
|
-
|
|
92
|
-
Returns:
|
|
93
|
-
str: The created SQL identifier object.
|
|
94
|
-
"""
|
|
95
|
-
...
|
|
96
|
-
|
|
97
|
-
@overload
|
|
98
|
-
@abstractmethod
|
|
99
|
-
def createCursor(self) -> Any: ...
|
|
100
|
-
|
|
101
|
-
@overload
|
|
102
|
-
@abstractmethod
|
|
103
|
-
def createCursor(self, emptyDataClass: DBDataModel) -> Any: ...
|
|
104
|
-
|
|
105
|
-
@abstractmethod
|
|
106
|
-
def createCursor(self, emptyDataClass: DBDataModel | None = None) -> Any:
|
|
107
|
-
"""
|
|
108
|
-
Creates a new cursor object.
|
|
109
|
-
|
|
110
|
-
Args:
|
|
111
|
-
emptyDataClass (T | None, optional): The data model to use for the cursor. Defaults to None.
|
|
112
|
-
|
|
113
|
-
Returns:
|
|
114
|
-
The created cursor object.
|
|
115
|
-
"""
|
|
116
|
-
...
|
|
117
|
-
|
|
118
|
-
@abstractmethod
|
|
119
|
-
def logQuery(self, cursor: Any, query: Any, params: tuple[Any, ...]) -> None:
|
|
120
|
-
"""
|
|
121
|
-
Logs the given query and parameters.
|
|
122
|
-
|
|
123
|
-
Args:
|
|
124
|
-
cursor (Any): The database cursor.
|
|
125
|
-
query (Any): The query to log.
|
|
126
|
-
params (tuple[Any, ...]): The parameters to log.
|
|
127
|
-
"""
|
|
128
|
-
...
|
|
129
|
-
|
|
130
|
-
@abstractmethod
|
|
131
|
-
def turnDataIntoModel(
|
|
132
|
-
self,
|
|
133
|
-
emptyDataClass: T,
|
|
134
|
-
dbData: dict[str, Any],
|
|
135
|
-
) -> T:
|
|
136
|
-
"""
|
|
137
|
-
Turns the given data into a data model.
|
|
138
|
-
By default we are pretty sure that there is no factory in the cursor,
|
|
139
|
-
So we need to create a new instance of the data model and fill it with data
|
|
140
|
-
|
|
141
|
-
Args:
|
|
142
|
-
emptyDataClass (T): The data model to use.
|
|
143
|
-
dbData (dict[str, Any]): The data to turn into a model.
|
|
144
|
-
|
|
145
|
-
Returns:
|
|
146
|
-
T: The data model filled with data.
|
|
147
|
-
"""
|
|
148
|
-
...
|
|
149
|
-
|
|
150
|
-
#####################
|
|
151
|
-
### Query methods ###
|
|
152
|
-
#####################
|
|
153
|
-
|
|
154
|
-
@abstractmethod
|
|
155
|
-
def filterQuery(self, schemaName: str | None, tableName: str) -> Any:
|
|
156
|
-
"""
|
|
157
|
-
Creates a SQL query to filter data from the given table.
|
|
158
|
-
|
|
159
|
-
Args:
|
|
160
|
-
schemaName (str | None): The name of the schema to filter data from.
|
|
161
|
-
tableName (str): The name of the table to filter data from.
|
|
162
|
-
|
|
163
|
-
Returns:
|
|
164
|
-
Any: The created SQL query object.
|
|
165
|
-
"""
|
|
166
|
-
...
|
|
167
|
-
|
|
168
|
-
@abstractmethod
|
|
169
|
-
def limitQuery(self, offset: int = 0, limit: int = 100) -> Any:
|
|
170
|
-
"""
|
|
171
|
-
Creates a SQL query to limit the number of results returned.
|
|
172
|
-
|
|
173
|
-
Args:
|
|
174
|
-
offset (int, optional): The number of results to skip. Defaults to 0.
|
|
175
|
-
limit (int, optional): The maximum number of results to return. Defaults to 100.
|
|
176
|
-
|
|
177
|
-
Returns:
|
|
178
|
-
Any: The created SQL query object.
|
|
179
|
-
"""
|
|
180
|
-
...
|
|
181
|
-
|
|
182
|
-
@abstractmethod
|
|
183
|
-
def getOne(
|
|
184
|
-
self,
|
|
185
|
-
emptyDataClass: Any,
|
|
186
|
-
customQuery: Any = None,
|
|
187
|
-
) -> Any:
|
|
188
|
-
"""
|
|
189
|
-
Retrieves a single record from the database.
|
|
190
|
-
|
|
191
|
-
Args:
|
|
192
|
-
emptyDataClass (Any): The data model to use for the query.
|
|
193
|
-
customQuery (Any, optional): The custom query to use for the query. Defaults to None.
|
|
194
|
-
|
|
195
|
-
Returns:
|
|
196
|
-
Any: The result of the query.
|
|
197
|
-
"""
|
|
198
|
-
...
|
|
199
|
-
|
|
200
|
-
@abstractmethod
|
|
201
|
-
def getByKey(
|
|
202
|
-
self,
|
|
203
|
-
emptyDataClass: Any,
|
|
204
|
-
idKey: str,
|
|
205
|
-
idValue: Any,
|
|
206
|
-
customQuery: Any = None,
|
|
207
|
-
) -> Any:
|
|
208
|
-
"""
|
|
209
|
-
Retrieves a single record from the database using the given key.
|
|
210
|
-
|
|
211
|
-
Args:
|
|
212
|
-
emptyDataClass (Any): The data model to use for the query.
|
|
213
|
-
idKey (str): The name of the key to use for the query.
|
|
214
|
-
idValue (Any): The value of the key to use for the query.
|
|
215
|
-
customQuery (Any, optional): The custom query to use for the query. Defaults to None.
|
|
216
|
-
|
|
217
|
-
Returns:
|
|
218
|
-
Any: The result of the query.
|
|
219
|
-
"""
|
|
220
|
-
...
|
|
221
|
-
|
|
222
|
-
@abstractmethod
|
|
223
|
-
def getAll(
|
|
224
|
-
self,
|
|
225
|
-
emptyDataClass: Any,
|
|
226
|
-
idKey: str | None = None,
|
|
227
|
-
idValue: Any | None = None,
|
|
228
|
-
orderBy: OrderByItem | None = None,
|
|
229
|
-
offset: int = 0,
|
|
230
|
-
limit: int = 100,
|
|
231
|
-
customQuery: Any = None,
|
|
232
|
-
) -> Any:
|
|
233
|
-
"""
|
|
234
|
-
Retrieves all records from the database.
|
|
235
|
-
|
|
236
|
-
Args:
|
|
237
|
-
emptyDataClass (T): The data model to use for the query.
|
|
238
|
-
idKey (str | None, optional): The name of the key to use for filtering. Defaults to None.
|
|
239
|
-
idValue (Any | None, optional): The value of the key to use for filtering. Defaults to None.
|
|
240
|
-
orderBy (OrderByItem | None, optional): The order by item to use for sorting. Defaults to None.
|
|
241
|
-
offset (int, optional): The number of results to skip. Defaults to 0.
|
|
242
|
-
limit (int, optional): The maximum number of results to return. Defaults to 100.
|
|
243
|
-
customQuery (Any, optional): The custom query to use for the query. Defaults to None.
|
|
244
|
-
|
|
245
|
-
Returns:
|
|
246
|
-
Any: The result of the query.
|
|
247
|
-
"""
|
|
248
|
-
...
|
|
249
|
-
|
|
250
|
-
@abstractmethod
|
|
251
|
-
def formatFilter(self, key: str, filter: Any) -> tuple[Any, ...]:
|
|
252
|
-
"""
|
|
253
|
-
Formats a filter for the query.
|
|
254
|
-
|
|
255
|
-
Args:
|
|
256
|
-
key (str): The key to format.
|
|
257
|
-
filter (Any): The filter to format.
|
|
258
|
-
"""
|
|
259
|
-
...
|
|
260
|
-
|
|
261
|
-
@abstractmethod
|
|
262
|
-
def createFilter(
|
|
263
|
-
self, filter: dict[str, Any] | None
|
|
264
|
-
) -> tuple[str, tuple[Any, ...]]:
|
|
265
|
-
"""
|
|
266
|
-
Creates a filter for the query.
|
|
267
|
-
|
|
268
|
-
Args:
|
|
269
|
-
filter (dict[str, Any] | None): The filter to create.
|
|
270
|
-
|
|
271
|
-
Returns:
|
|
272
|
-
tuple[str, tuple[Any, ...]]: The created filter.
|
|
273
|
-
"""
|
|
274
|
-
...
|
|
275
|
-
|
|
276
|
-
@abstractmethod
|
|
277
|
-
def getFiltered(
|
|
278
|
-
self,
|
|
279
|
-
emptyDataClass: Any,
|
|
280
|
-
filter: dict[str, Any],
|
|
281
|
-
orderBy: OrderByItem | None = None,
|
|
282
|
-
offset: int = 0,
|
|
283
|
-
limit: int = 100,
|
|
284
|
-
customQuery: Any = None,
|
|
285
|
-
) -> Any: ...
|
|
286
|
-
|
|
287
|
-
@abstractmethod
|
|
288
|
-
def _store(
|
|
289
|
-
self,
|
|
290
|
-
emptyDataClass: DBDataModel,
|
|
291
|
-
schemaName: str | None,
|
|
292
|
-
tableName: str,
|
|
293
|
-
storeData: dict[str, Any],
|
|
294
|
-
idKey: str,
|
|
295
|
-
) -> Any:
|
|
296
|
-
"""
|
|
297
|
-
Stores a record in the database.
|
|
298
|
-
|
|
299
|
-
Args:
|
|
300
|
-
emptyDataClass (DBDataModel): The data model to use for the query.
|
|
301
|
-
schemaName (str | None): The name of the schema to store the record in.
|
|
302
|
-
tableName (str): The name of the table to store the record in.
|
|
303
|
-
storeData (dict[str, Any]): The data to store.
|
|
304
|
-
idKey (str): The name of the key to use for the query.
|
|
305
|
-
|
|
306
|
-
Returns:
|
|
307
|
-
Any: The id of the record and the number of affected rows.
|
|
308
|
-
"""
|
|
309
|
-
...
|
|
310
|
-
|
|
311
|
-
@overload
|
|
312
|
-
@abstractmethod
|
|
313
|
-
def store(self, records: T) -> Any: # type: ignore
|
|
314
|
-
...
|
|
315
|
-
|
|
316
|
-
@overload
|
|
317
|
-
@abstractmethod
|
|
318
|
-
def store(self, records: list[T]) -> Any: ...
|
|
319
|
-
|
|
320
|
-
@abstractmethod
|
|
321
|
-
def store(self, records: T | list[T]) -> Any:
|
|
322
|
-
"""
|
|
323
|
-
Stores a record or a list of records in the database.
|
|
324
|
-
|
|
325
|
-
Args:
|
|
326
|
-
records (T | list[T]): The record or records to store.
|
|
327
|
-
|
|
328
|
-
Returns:
|
|
329
|
-
Any: The id of the record and
|
|
330
|
-
the number of affected rows for a single record or a list of
|
|
331
|
-
ids and the number of affected rows for a list of records.
|
|
332
|
-
"""
|
|
333
|
-
...
|
|
334
|
-
|
|
335
|
-
@abstractmethod
|
|
336
|
-
def _update(
|
|
337
|
-
self,
|
|
338
|
-
emptyDataClass: DBDataModel,
|
|
339
|
-
schemaName: str | None,
|
|
340
|
-
tableName: str,
|
|
341
|
-
updateData: dict[str, Any],
|
|
342
|
-
updateId: tuple[str, Any],
|
|
343
|
-
) -> Any:
|
|
344
|
-
"""
|
|
345
|
-
Updates a record in the database.
|
|
346
|
-
|
|
347
|
-
Args:
|
|
348
|
-
emptyDataClass (DBDataModel): The data model to use for the query.
|
|
349
|
-
schemaName (str | None): The name of the schema to update the record in.
|
|
350
|
-
tableName (str): The name of the table to update the record in.
|
|
351
|
-
updateData (dict[str, Any]): The data to update.
|
|
352
|
-
updateId (tuple[str, Any]): The id of the record to update.
|
|
353
|
-
|
|
354
|
-
Returns:
|
|
355
|
-
Any: The number of affected rows.
|
|
356
|
-
"""
|
|
357
|
-
...
|
|
358
|
-
|
|
359
|
-
@overload
|
|
360
|
-
@abstractmethod
|
|
361
|
-
def update(self, records: T) -> Any: # type: ignore
|
|
362
|
-
...
|
|
363
|
-
|
|
364
|
-
@overload
|
|
365
|
-
@abstractmethod
|
|
366
|
-
def update(self, records: list[T]) -> Any: ...
|
|
367
|
-
|
|
368
|
-
@abstractmethod
|
|
369
|
-
def update(self, records: T | list[T]) -> Any:
|
|
370
|
-
"""
|
|
371
|
-
Updates a record or a list of records in the database.
|
|
372
|
-
|
|
373
|
-
Args:
|
|
374
|
-
records (T | list[T]): The record or records to update.
|
|
375
|
-
|
|
376
|
-
Returns:
|
|
377
|
-
Any: The number of affected rows for a single record or a list of
|
|
378
|
-
affected rows for a list of records.
|
|
379
|
-
"""
|
|
380
|
-
...
|
|
381
|
-
|
|
382
|
-
@abstractmethod
|
|
383
|
-
def updateData(
|
|
384
|
-
self,
|
|
385
|
-
record: DBDataModel,
|
|
386
|
-
updateData: dict[str, Any],
|
|
387
|
-
updateIdKey: str | None = None,
|
|
388
|
-
updateIdValue: Any = None,
|
|
389
|
-
) -> Any: ...
|
|
390
|
-
|
|
391
|
-
@abstractmethod
|
|
392
|
-
def _delete(
|
|
393
|
-
self,
|
|
394
|
-
emptyDataClass: DBDataModel,
|
|
395
|
-
schemaName: str | None,
|
|
396
|
-
tableName: str,
|
|
397
|
-
deleteId: tuple[str, Any],
|
|
398
|
-
) -> Any:
|
|
399
|
-
"""
|
|
400
|
-
Deletes a record from the database.
|
|
401
|
-
|
|
402
|
-
Args:
|
|
403
|
-
emptyDataClass (DBDataModel): The data model to use for the query.
|
|
404
|
-
schemaName (str | None): The name of the schema to delete the record from.
|
|
405
|
-
tableName (str): The name of the table to delete the record from.
|
|
406
|
-
deleteId (tuple[str, Any]): The id of the record to delete.
|
|
407
|
-
|
|
408
|
-
Returns:
|
|
409
|
-
Any: The number of affected rows.
|
|
410
|
-
"""
|
|
411
|
-
...
|
|
412
|
-
|
|
413
|
-
@overload
|
|
414
|
-
@abstractmethod
|
|
415
|
-
def delete(self, records: T) -> Any: # type: ignore
|
|
416
|
-
...
|
|
417
|
-
|
|
418
|
-
@overload
|
|
419
|
-
@abstractmethod
|
|
420
|
-
def delete(self, records: list[T]) -> Any: ...
|
|
421
|
-
|
|
422
|
-
@abstractmethod
|
|
423
|
-
def delete(self, records: T | list[T]) -> Any:
|
|
424
|
-
"""
|
|
425
|
-
Deletes a record or a list of records from the database.
|
|
426
|
-
|
|
427
|
-
Args:
|
|
428
|
-
records (T | list[T]): The record or records to delete.
|
|
429
|
-
|
|
430
|
-
Returns:
|
|
431
|
-
Any: The number of affected rows for a single record or a list of
|
|
432
|
-
affected rows for a list of records.
|
|
433
|
-
"""
|
|
434
|
-
...
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
database_wrapper/__init__.py,sha256=pwXuJmQJxTRehMTp3F_QcsqV8LtHJSlmiA_DedgGs5I,866
|
|
2
|
-
database_wrapper/config.py,sha256=t4oB1cObVSl_ArKsdV-ZvTPqJEKINS3QvquQMrWC6DA,334
|
|
3
|
-
database_wrapper/db_backend.py,sha256=iQd1yVsLumutfoOmWY-XAAiLg00_I-IueOv_RtO_7ew,5068
|
|
4
|
-
database_wrapper/db_data_model.py,sha256=RzOVITczh6IgnBTjur6XDdIj5pkv7fXPl-AjM4xOB0Q,9904
|
|
5
|
-
database_wrapper/db_wrapper.py,sha256=EvJbxhaUHIT74zkV5yE-9JgE-i5ZA46PxDy1Y95F_gc,25157
|
|
6
|
-
database_wrapper/db_wrapper_async.py,sha256=ZpbAkM9MTOdzlyfNRuBlWMuyoTPvhKBEL3wKEQTtSsI,25693
|
|
7
|
-
database_wrapper/db_wrapper_interface.py,sha256=ocEAHf3pmuhSjBq7H2mTjF7RMDDio6IUOQV-sPKxKp4,11979
|
|
8
|
-
database_wrapper/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
database_wrapper/utils/__init__.py,sha256=mnewmY38-837VAh4f42hvpMUBVUjOLoMtIfdZBxbkg0,134
|
|
10
|
-
database_wrapper/utils/dataclass_addons.py,sha256=2n0m_WGZGtiiBd8JNwomUvfkULvMg2C_1kwe-Sq-Z7A,702
|
|
11
|
-
database_wrapper/utils/timer.py,sha256=ZJpVMsQ7oHHgyuqMOxVee1fZD78kcDrP4c8gHug3xGU,8927
|
|
12
|
-
database_wrapper-0.1.33.dist-info/METADATA,sha256=i4cikLY68wbzhqs4EzNg6oRdf7nb_0ac09CaAkMAmMk,3370
|
|
13
|
-
database_wrapper-0.1.33.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
14
|
-
database_wrapper-0.1.33.dist-info/top_level.txt,sha256=QcnS4ocJygxcKE5eoOqriuja306oVu-zJRn6yjRRhBw,17
|
|
15
|
-
database_wrapper-0.1.33.dist-info/RECORD,,
|
|
File without changes
|