database-wrapper 0.1.38__py3-none-any.whl → 0.1.42__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/config.py +3 -3
- database_wrapper/db_wrapper.py +23 -69
- database_wrapper/db_wrapper_async.py +15 -68
- database_wrapper/db_wrapper_mixin.py +13 -5
- {database_wrapper-0.1.38.dist-info → database_wrapper-0.1.42.dist-info}/METADATA +5 -5
- {database_wrapper-0.1.38.dist-info → database_wrapper-0.1.42.dist-info}/RECORD +8 -8
- {database_wrapper-0.1.38.dist-info → database_wrapper-0.1.42.dist-info}/WHEEL +0 -0
- {database_wrapper-0.1.38.dist-info → database_wrapper-0.1.42.dist-info}/top_level.txt +0 -0
database_wrapper/config.py
CHANGED
|
@@ -3,7 +3,7 @@ from typing import Any
|
|
|
3
3
|
CONFIG: dict[str, Any] = {
|
|
4
4
|
# These are supposed to be set automatically by a git pre-compile script
|
|
5
5
|
# They are one git commit hash behind, if used automatically
|
|
6
|
-
"git_commit_hash": "
|
|
7
|
-
"git_commit_date": "
|
|
8
|
-
"app_version": "0.1.
|
|
6
|
+
"git_commit_hash": "365f062181488aa4bd2f56e694fce6b26a113b1b",
|
|
7
|
+
"git_commit_date": "15.11.2024 02:01",
|
|
8
|
+
"app_version": "0.1.42",
|
|
9
9
|
}
|
database_wrapper/db_wrapper.py
CHANGED
|
@@ -42,7 +42,14 @@ class DBWrapper(DBWrapperMixin):
|
|
|
42
42
|
Returns:
|
|
43
43
|
The created cursor object.
|
|
44
44
|
"""
|
|
45
|
-
|
|
45
|
+
if self.db is None and self.dbConn is None:
|
|
46
|
+
raise ValueError(
|
|
47
|
+
"Database object and connection is not properly initialized"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if self.dbConn is not None:
|
|
51
|
+
return self.dbConn.cursor()
|
|
52
|
+
|
|
46
53
|
return self.db.cursor
|
|
47
54
|
|
|
48
55
|
#####################
|
|
@@ -65,12 +72,7 @@ class DBWrapper(DBWrapperMixin):
|
|
|
65
72
|
Returns:
|
|
66
73
|
DataModelType | None: The result of the query.
|
|
67
74
|
"""
|
|
68
|
-
#
|
|
69
|
-
_query = (
|
|
70
|
-
customQuery
|
|
71
|
-
or emptyDataClass.queryBase()
|
|
72
|
-
or self.filterQuery(emptyDataClass.schemaName, emptyDataClass.tableName)
|
|
73
|
-
)
|
|
75
|
+
# Figure out the id key and value
|
|
74
76
|
idKey = emptyDataClass.idKey
|
|
75
77
|
idValue = emptyDataClass.id
|
|
76
78
|
if not idKey:
|
|
@@ -78,32 +80,12 @@ class DBWrapper(DBWrapperMixin):
|
|
|
78
80
|
if not idValue:
|
|
79
81
|
raise ValueError("Id value is not set")
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
# Create a new cursor
|
|
88
|
-
newCursor = self.createCursor(emptyDataClass)
|
|
89
|
-
|
|
90
|
-
# Log
|
|
91
|
-
self.logQuery(newCursor, querySql, _params)
|
|
92
|
-
|
|
93
|
-
# Load data
|
|
94
|
-
try:
|
|
95
|
-
newCursor.execute(querySql, _params)
|
|
96
|
-
|
|
97
|
-
# Fetch one row
|
|
98
|
-
row = newCursor.fetchone()
|
|
99
|
-
if row is None:
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
# Turn data into model
|
|
103
|
-
return self.turnDataIntoModel(emptyDataClass, row)
|
|
104
|
-
finally:
|
|
105
|
-
# Close the cursor
|
|
106
|
-
newCursor.close()
|
|
83
|
+
# Get the record
|
|
84
|
+
res = self.getAll(
|
|
85
|
+
emptyDataClass, idKey, idValue, limit=1, customQuery=customQuery
|
|
86
|
+
)
|
|
87
|
+
for row in res:
|
|
88
|
+
return row
|
|
107
89
|
|
|
108
90
|
def getByKey(
|
|
109
91
|
self,
|
|
@@ -124,39 +106,12 @@ class DBWrapper(DBWrapperMixin):
|
|
|
124
106
|
Returns:
|
|
125
107
|
DataModelType | None: The result of the query.
|
|
126
108
|
"""
|
|
127
|
-
#
|
|
128
|
-
|
|
129
|
-
customQuery
|
|
130
|
-
or emptyDataClass.queryBase()
|
|
131
|
-
or self.filterQuery(emptyDataClass.schemaName, emptyDataClass.tableName)
|
|
109
|
+
# Get the record
|
|
110
|
+
res = self.getAll(
|
|
111
|
+
emptyDataClass, idKey, idValue, limit=1, customQuery=customQuery
|
|
132
112
|
)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
# Create a SQL object for the query and format it
|
|
137
|
-
querySql = self._formatFilterQuery(_query, _filter, None, None)
|
|
138
|
-
|
|
139
|
-
# Create a new cursor
|
|
140
|
-
newCursor = self.createCursor(emptyDataClass)
|
|
141
|
-
|
|
142
|
-
# Log
|
|
143
|
-
self.logQuery(newCursor, querySql, _params)
|
|
144
|
-
|
|
145
|
-
# Load data
|
|
146
|
-
try:
|
|
147
|
-
newCursor.execute(querySql, _params)
|
|
148
|
-
|
|
149
|
-
# Fetch one row
|
|
150
|
-
row = newCursor.fetchone()
|
|
151
|
-
if row is None:
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
# Turn data into model
|
|
155
|
-
return self.turnDataIntoModel(emptyDataClass, row)
|
|
156
|
-
|
|
157
|
-
finally:
|
|
158
|
-
# Close the cursor
|
|
159
|
-
newCursor.close()
|
|
113
|
+
for row in res:
|
|
114
|
+
return row
|
|
160
115
|
|
|
161
116
|
def getAll(
|
|
162
117
|
self,
|
|
@@ -191,11 +146,10 @@ class DBWrapper(DBWrapperMixin):
|
|
|
191
146
|
)
|
|
192
147
|
_params: tuple[Any, ...] = ()
|
|
193
148
|
_filter = ""
|
|
149
|
+
|
|
150
|
+
# TODO: Rewrite this so that filter method with loop is not used here
|
|
194
151
|
if idKey and idValue:
|
|
195
|
-
_filter = (
|
|
196
|
-
f"WHERE {self.makeIdentifier(emptyDataClass.tableAlias, idKey)} = %s"
|
|
197
|
-
)
|
|
198
|
-
_params = (idValue,)
|
|
152
|
+
(_filter, _params) = self.createFilter({idKey: idValue})
|
|
199
153
|
|
|
200
154
|
# Order and limit
|
|
201
155
|
_order = self.orderQuery(orderBy)
|
|
@@ -66,12 +66,7 @@ class DBWrapperAsync(DBWrapperMixin):
|
|
|
66
66
|
Returns:
|
|
67
67
|
DataModelType | None: The result of the query.
|
|
68
68
|
"""
|
|
69
|
-
#
|
|
70
|
-
_query = (
|
|
71
|
-
customQuery
|
|
72
|
-
or emptyDataClass.queryBase()
|
|
73
|
-
or self.filterQuery(emptyDataClass.schemaName, emptyDataClass.tableName)
|
|
74
|
-
)
|
|
69
|
+
# Figure out the id key and value
|
|
75
70
|
idKey = emptyDataClass.idKey
|
|
76
71
|
idValue = emptyDataClass.id
|
|
77
72
|
if not idKey:
|
|
@@ -79,32 +74,12 @@ class DBWrapperAsync(DBWrapperMixin):
|
|
|
79
74
|
if not idValue:
|
|
80
75
|
raise ValueError("Id value is not set")
|
|
81
76
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
# Create a new cursor
|
|
89
|
-
newCursor = await self.createCursor(emptyDataClass)
|
|
90
|
-
|
|
91
|
-
# Log
|
|
92
|
-
self.logQuery(newCursor, querySql, _params)
|
|
93
|
-
|
|
94
|
-
# Load data
|
|
95
|
-
try:
|
|
96
|
-
await newCursor.execute(querySql, _params)
|
|
97
|
-
|
|
98
|
-
# Fetch one row
|
|
99
|
-
row = await newCursor.fetchone()
|
|
100
|
-
if row is None:
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
# Turn data into model
|
|
104
|
-
return self.turnDataIntoModel(emptyDataClass, row)
|
|
105
|
-
finally:
|
|
106
|
-
# Close the cursor
|
|
107
|
-
await newCursor.close()
|
|
77
|
+
# Get the record
|
|
78
|
+
res = self.getAll(
|
|
79
|
+
emptyDataClass, idKey, idValue, limit=1, customQuery=customQuery
|
|
80
|
+
)
|
|
81
|
+
async for row in res:
|
|
82
|
+
return row
|
|
108
83
|
|
|
109
84
|
async def getByKey(
|
|
110
85
|
self,
|
|
@@ -125,39 +100,12 @@ class DBWrapperAsync(DBWrapperMixin):
|
|
|
125
100
|
Returns:
|
|
126
101
|
DataModelType | None: The result of the query.
|
|
127
102
|
"""
|
|
128
|
-
#
|
|
129
|
-
|
|
130
|
-
customQuery
|
|
131
|
-
or emptyDataClass.queryBase()
|
|
132
|
-
or self.filterQuery(emptyDataClass.schemaName, emptyDataClass.tableName)
|
|
103
|
+
# Get the record
|
|
104
|
+
res = self.getAll(
|
|
105
|
+
emptyDataClass, idKey, idValue, limit=1, customQuery=customQuery
|
|
133
106
|
)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
# Create a SQL object for the query and format it
|
|
138
|
-
querySql = self._formatFilterQuery(_query, _filter, None, None)
|
|
139
|
-
|
|
140
|
-
# Create a new cursor
|
|
141
|
-
newCursor = await self.createCursor(emptyDataClass)
|
|
142
|
-
|
|
143
|
-
# Log
|
|
144
|
-
self.logQuery(newCursor, querySql, _params)
|
|
145
|
-
|
|
146
|
-
# Load data
|
|
147
|
-
try:
|
|
148
|
-
await newCursor.execute(querySql, _params)
|
|
149
|
-
|
|
150
|
-
# Fetch one row
|
|
151
|
-
row = await newCursor.fetchone()
|
|
152
|
-
if row is None:
|
|
153
|
-
return
|
|
154
|
-
|
|
155
|
-
# Turn data into model
|
|
156
|
-
return self.turnDataIntoModel(emptyDataClass, row)
|
|
157
|
-
|
|
158
|
-
finally:
|
|
159
|
-
# Close the cursor
|
|
160
|
-
await newCursor.close()
|
|
107
|
+
async for row in res:
|
|
108
|
+
return row
|
|
161
109
|
|
|
162
110
|
async def getAll(
|
|
163
111
|
self,
|
|
@@ -192,11 +140,10 @@ class DBWrapperAsync(DBWrapperMixin):
|
|
|
192
140
|
)
|
|
193
141
|
_params: tuple[Any, ...] = ()
|
|
194
142
|
_filter = None
|
|
143
|
+
|
|
144
|
+
# TODO: Rewrite this so that filter method with loop is not used here
|
|
195
145
|
if idKey and idValue:
|
|
196
|
-
_filter = (
|
|
197
|
-
f"WHERE {self.makeIdentifier(emptyDataClass.tableAlias, idKey)} = %s"
|
|
198
|
-
)
|
|
199
|
-
_params = (idValue,)
|
|
146
|
+
(_filter, _params) = self.createFilter({idKey: idValue})
|
|
200
147
|
|
|
201
148
|
# Order and limit
|
|
202
149
|
_order = self.orderQuery(orderBy)
|
|
@@ -2,7 +2,6 @@ import logging
|
|
|
2
2
|
|
|
3
3
|
from typing import cast, Any
|
|
4
4
|
|
|
5
|
-
from .db_backend import DatabaseBackend
|
|
6
5
|
from .common import OrderByItem, NoParam, DataModelType
|
|
7
6
|
|
|
8
7
|
|
|
@@ -80,22 +79,31 @@ class DBWrapperMixin:
|
|
|
80
79
|
### Setters ###
|
|
81
80
|
###############
|
|
82
81
|
|
|
83
|
-
def
|
|
82
|
+
def setDb(self, db: Any) -> None:
|
|
84
83
|
"""
|
|
85
84
|
Updates the database backend object.
|
|
86
85
|
|
|
87
86
|
Args:
|
|
88
|
-
db (
|
|
87
|
+
db (Any): The new database backend object.
|
|
89
88
|
"""
|
|
89
|
+
if db is None:
|
|
90
|
+
del self.db
|
|
91
|
+
return
|
|
92
|
+
|
|
90
93
|
self.db = db
|
|
91
94
|
|
|
92
|
-
def
|
|
95
|
+
def setDbConn(self, dbConn: Any) -> None:
|
|
93
96
|
"""
|
|
94
97
|
Updates the database connection object.
|
|
95
98
|
|
|
96
99
|
Args:
|
|
97
100
|
dbConn (Any): The new database connection object.
|
|
98
101
|
"""
|
|
102
|
+
|
|
103
|
+
if dbConn is None:
|
|
104
|
+
del self.dbConn
|
|
105
|
+
return
|
|
106
|
+
|
|
99
107
|
self.dbConn = dbConn
|
|
100
108
|
|
|
101
109
|
######################
|
|
@@ -268,7 +276,7 @@ class DBWrapperMixin:
|
|
|
268
276
|
|
|
269
277
|
def createFilter(
|
|
270
278
|
self, filter: dict[str, Any] | None
|
|
271
|
-
) -> tuple[
|
|
279
|
+
) -> tuple[Any, tuple[Any, ...]]:
|
|
272
280
|
if filter is None or len(filter) == 0:
|
|
273
281
|
return ("", tuple())
|
|
274
282
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: database_wrapper
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.42
|
|
4
4
|
Summary: A Different Approach to Database Wrappers in Python
|
|
5
5
|
Author-email: Gints Murans <gm@gm.lv>
|
|
6
6
|
License: GNU General Public License v3.0 (GPL-3.0)
|
|
@@ -46,13 +46,13 @@ Requires-Dist: psycopg[pool] >=3.2.0 ; extra == 'dev'
|
|
|
46
46
|
Requires-Dist: mysqlclient >=2.2.2 ; extra == 'dev'
|
|
47
47
|
Requires-Dist: pymssql >=2.2.10 ; extra == 'dev'
|
|
48
48
|
Provides-Extra: mssql
|
|
49
|
-
Requires-Dist: database-wrapper-mssql ==0.1.
|
|
49
|
+
Requires-Dist: database-wrapper-mssql ==0.1.42 ; extra == 'mssql'
|
|
50
50
|
Provides-Extra: mysql
|
|
51
|
-
Requires-Dist: database-wrapper-mysql ==0.1.
|
|
51
|
+
Requires-Dist: database-wrapper-mysql ==0.1.42 ; extra == 'mysql'
|
|
52
52
|
Provides-Extra: pgsql
|
|
53
|
-
Requires-Dist: database-wrapper-pgsql ==0.1.
|
|
53
|
+
Requires-Dist: database-wrapper-pgsql ==0.1.42 ; extra == 'pgsql'
|
|
54
54
|
Provides-Extra: sqlite
|
|
55
|
-
Requires-Dist: database-wrapper-sqlite ==0.1.
|
|
55
|
+
Requires-Dist: database-wrapper-sqlite ==0.1.42 ; extra == 'sqlite'
|
|
56
56
|
|
|
57
57
|
# database_wrapper
|
|
58
58
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
database_wrapper/__init__.py,sha256=amoShlhRpOhrFbGeKbdq47H5omcVRd4xWG-RUX7bdIk,830
|
|
2
2
|
database_wrapper/common.py,sha256=fsxe28o_4xCrotPbB274dmzQ9rOyes0sBtcHog-9RVc,258
|
|
3
|
-
database_wrapper/config.py,sha256=
|
|
3
|
+
database_wrapper/config.py,sha256=w7NSHEnvNqa6zdULt1estaAC-9Vqj72jV38tGrbRpqo,334
|
|
4
4
|
database_wrapper/db_backend.py,sha256=iQd1yVsLumutfoOmWY-XAAiLg00_I-IueOv_RtO_7ew,5068
|
|
5
5
|
database_wrapper/db_data_model.py,sha256=njef4LR7XQcTdob961t1DQ7q3i2dzfVrFyuAtD3YYwQ,12181
|
|
6
|
-
database_wrapper/db_wrapper.py,sha256=
|
|
7
|
-
database_wrapper/db_wrapper_async.py,sha256=
|
|
8
|
-
database_wrapper/db_wrapper_mixin.py,sha256
|
|
6
|
+
database_wrapper/db_wrapper.py,sha256=O5H7Q8xvvzN4p7KL_NnHflY-EZCfw9TM5mYBzRuJfZA,16488
|
|
7
|
+
database_wrapper/db_wrapper_async.py,sha256=4K-01_UtNxaRgN5qB3j1O2eBX2cOW0xi2ZJJimnqgYw,16714
|
|
8
|
+
database_wrapper/db_wrapper_mixin.py,sha256=-k8Gna_iGE5Gz1gRsVP8sOkUbwX3djjCWeM3ZkGKT7E,10570
|
|
9
9
|
database_wrapper/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
database_wrapper/utils/__init__.py,sha256=mnewmY38-837VAh4f42hvpMUBVUjOLoMtIfdZBxbkg0,134
|
|
11
11
|
database_wrapper/utils/dataclass_addons.py,sha256=5_ZAj8h-4RtimEM-b9lo6TXi4qYVTf7KIjTtu0jzAS4,762
|
|
12
12
|
database_wrapper/utils/timer.py,sha256=ZJpVMsQ7oHHgyuqMOxVee1fZD78kcDrP4c8gHug3xGU,8927
|
|
13
|
-
database_wrapper-0.1.
|
|
14
|
-
database_wrapper-0.1.
|
|
15
|
-
database_wrapper-0.1.
|
|
16
|
-
database_wrapper-0.1.
|
|
13
|
+
database_wrapper-0.1.42.dist-info/METADATA,sha256=o8geerZ2YpCl8NWntuHcr-7e_AT2V4jWsv7-KOsKQV0,3370
|
|
14
|
+
database_wrapper-0.1.42.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
|
|
15
|
+
database_wrapper-0.1.42.dist-info/top_level.txt,sha256=QcnS4ocJygxcKE5eoOqriuja306oVu-zJRn6yjRRhBw,17
|
|
16
|
+
database_wrapper-0.1.42.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|