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