database-wrapper 0.1.86__py3-none-any.whl → 0.1.88__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.
@@ -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": "b117e5a27fe8408b8245baae74eda5aefdcce995",
7
- "git_commit_date": "25.04.2025 21:32",
8
- "app_version": "0.1.86",
6
+ "git_commit_hash": "3b140044c9c3f01102ec24e8739906b577491571",
7
+ "git_commit_date": "19.06.2025 12:03",
8
+ "app_version": "0.1.88",
9
9
  }
@@ -90,9 +90,7 @@ class DatabaseBackend:
90
90
  self.cursor = None
91
91
  self.shutdownRequested = Event()
92
92
  self.contextConnection = ContextVar(f"db_connection_{self.name}", default=None)
93
- self.contextConnectionAsync = ContextVar(
94
- f"db_connection_{self.name}_async", default=None
95
- )
93
+ self.contextConnectionAsync = ContextVar(f"db_connection_{self.name}_async", default=None)
96
94
 
97
95
  def __del__(self) -> None:
98
96
  """What to do when class is destroyed"""
@@ -147,14 +145,22 @@ class DatabaseBackend:
147
145
 
148
146
  def close(self) -> Any:
149
147
  """Close connections"""
150
- if self.cursor:
151
- self.logger.debug("Closing cursor")
152
- self.cursor.close()
148
+ try:
149
+ if self.cursor:
150
+ self.logger.debug("Closing cursor")
151
+ self.cursor.close()
152
+ except Exception as e:
153
+ self.logger.debug(f"Error while closing cursor: {e}")
154
+ finally:
153
155
  self.cursor = None
154
156
 
155
- if self.connection:
156
- self.logger.debug("Closing connection")
157
- self.connection.close()
157
+ try:
158
+ if self.connection:
159
+ self.logger.debug("Closing connection")
160
+ self.connection.close()
161
+ except Exception as e:
162
+ self.logger.debug(f"Error while closing connection: {e}")
163
+ finally:
158
164
  self.connection = None
159
165
 
160
166
  def newConnection(self) -> Any:
@@ -227,9 +233,7 @@ class DatabaseBackend:
227
233
  s.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 3)
228
234
  # To set timeout for an RTO you must set TCP_USER_TIMEOUT timeout
229
235
  # (in milliseconds) for socket.
230
- s.setsockopt(
231
- socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, self.connectionTimeout * 1000
232
- )
236
+ s.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, self.connectionTimeout * 1000)
233
237
 
234
238
  ####################
235
239
  ### Transactions ###
@@ -25,6 +25,7 @@ class MetadataDict(TypedDict):
25
25
  serialize: NotRequired[Callable[[Any], Any] | SerializeType | None]
26
26
  deserialize: NotRequired[Callable[[Any], Any] | None]
27
27
  enum_class: NotRequired[Type[Enum] | None]
28
+ timezone: NotRequired[str | datetime.tzinfo | None]
28
29
 
29
30
 
30
31
  @dataclass
@@ -137,8 +138,9 @@ class DBDataModel:
137
138
  # Here we actually need to deserialize the value to correct class type
138
139
  serialize = metadata.get("serialize", None)
139
140
  enumClass = metadata.get("enum_class", None)
141
+ timezone = metadata.get("timezone", None)
140
142
  if serialize is not None and isinstance(serialize, SerializeType):
141
- value = deserializeValue(value, serialize, enumClass)
143
+ value = deserializeValue(value, serialize, enumClass, timezone)
142
144
  setattr(self, fieldName, value)
143
145
 
144
146
  else:
@@ -4,6 +4,7 @@ import json
4
4
  from decimal import Decimal
5
5
  from enum import Enum
6
6
  from typing import Any, Type
7
+ from zoneinfo import ZoneInfo
7
8
 
8
9
 
9
10
  class SerializeType(Enum):
@@ -47,6 +48,7 @@ def deserializeValue(
47
48
  value: Any,
48
49
  sType: SerializeType,
49
50
  enumClass: Type[Enum] | None = None,
51
+ timezone: str | datetime.tzinfo | None = None,
50
52
  ) -> Any:
51
53
  if sType == SerializeType.DATETIME:
52
54
  if isinstance(value, datetime.datetime):
@@ -57,7 +59,11 @@ def deserializeValue(
57
59
  timestamp = float(value)
58
60
  if timestamp > 1e10: # Check if timestamp is in milliseconds
59
61
  timestamp /= 1000
60
- return datetime.datetime.fromtimestamp(timestamp)
62
+
63
+ if timezone is not None and isinstance(timezone, str):
64
+ timezone = ZoneInfo(timezone)
65
+
66
+ return datetime.datetime.fromtimestamp(timestamp, tz=timezone)
61
67
 
62
68
  return datetime.datetime.fromisoformat(value)
63
69
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: database_wrapper
3
- Version: 0.1.86
3
+ Version: 0.1.88
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)
@@ -33,13 +33,13 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
33
33
  Requires-Python: >=3.8
34
34
  Description-Content-Type: text/markdown
35
35
  Provides-Extra: pgsql
36
- Requires-Dist: database_wrapper_pgsql==0.1.86; extra == "pgsql"
36
+ Requires-Dist: database_wrapper_pgsql==0.1.88; extra == "pgsql"
37
37
  Provides-Extra: mysql
38
- Requires-Dist: database_wrapper_mysql==0.1.86; extra == "mysql"
38
+ Requires-Dist: database_wrapper_mysql==0.1.88; extra == "mysql"
39
39
  Provides-Extra: mssql
40
- Requires-Dist: database_wrapper_mssql==0.1.86; extra == "mssql"
40
+ Requires-Dist: database_wrapper_mssql==0.1.88; extra == "mssql"
41
41
  Provides-Extra: sqlite
42
- Requires-Dist: database_wrapper_sqlite==0.1.86; extra == "sqlite"
42
+ Requires-Dist: database_wrapper_sqlite==0.1.88; extra == "sqlite"
43
43
  Provides-Extra: all
44
44
  Requires-Dist: database_wrapper[mssql,mysql,pgsql,sqlite]; extra == "all"
45
45
  Provides-Extra: dev
@@ -1,17 +1,17 @@
1
1
  database_wrapper/__init__.py,sha256=p-HLz9_zByIUeAS1tVxS7ZieslsryHSLw_IKZphqB7w,1200
2
2
  database_wrapper/abc.py,sha256=JiQo6Yfv7xALrrHeICJCSgmyP2gHrp16Ov83mPBTGbE,2058
3
3
  database_wrapper/common.py,sha256=fsxe28o_4xCrotPbB274dmzQ9rOyes0sBtcHog-9RVc,258
4
- database_wrapper/config.py,sha256=kWelGxk53aaNirxNWNFJXhT9O7zKOMM9avqAeKIe4Tw,334
5
- database_wrapper/db_backend.py,sha256=cMpUj-GOcrr-wVFG2ztKyTd65u50R0kmQ71Lx6GXgd0,7866
6
- database_wrapper/db_data_model.py,sha256=3NcxWr6Sk_Ixx1QPLWZfJLwxVqN391IZ1_K4WZMNJRE,14181
4
+ database_wrapper/config.py,sha256=yL9l-63BC2G4E8AX3ydpkFx3vAYgp-6_cp7mFlV5TyI,334
5
+ database_wrapper/db_backend.py,sha256=yfJHdEULvKx_hU_yUfm7C-1H6VYlh_LLlhkvKw_ZGQs,8104
6
+ database_wrapper/db_data_model.py,sha256=EDYmmmus7L7VMBi4aTCT9EoB0V0PXaOBVX-v5NG90PA,14301
7
7
  database_wrapper/db_wrapper.py,sha256=nsFHax43Zz8L3sBih9kVlnAvZWC2hv9U7V_MICbE0RY,14353
8
8
  database_wrapper/db_wrapper_async.py,sha256=8D4Oa0F6uPdjpH-cvmUPXLmbz35NLA7oa2MShIPourc,14737
9
9
  database_wrapper/db_wrapper_mixin.py,sha256=GR6Zn-2GygzzSaFWPIqkiI6mZ8oWqKY_Sc-MeUp6SG8,9966
10
10
  database_wrapper/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- database_wrapper/serialization.py,sha256=McLVLRlJ60OI2xHwnKD-0d3qHb5U8KTpz1P19SphxL8,2068
11
+ database_wrapper/serialization.py,sha256=6lW_q1BKdZpRfi6PEbnBh-kYcLMFFrdxpRHgT8WZG34,2277
12
12
  database_wrapper/utils/__init__.py,sha256=uC8YaJqfyFIZIeNdTRTbZwcOUVhmnS5eyOG-9gMs70c,96
13
13
  database_wrapper/utils/dataclass_addons.py,sha256=r8DD40tXA_DLMQJx62UqVaRe4Gr9BSOmChLRhxawet4,770
14
- database_wrapper-0.1.86.dist-info/METADATA,sha256=V4VLeqJRAQojIJa6kPfqNHOs9k5C9Db_mrzpluJAH_M,3440
15
- database_wrapper-0.1.86.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
16
- database_wrapper-0.1.86.dist-info/top_level.txt,sha256=QcnS4ocJygxcKE5eoOqriuja306oVu-zJRn6yjRRhBw,17
17
- database_wrapper-0.1.86.dist-info/RECORD,,
14
+ database_wrapper-0.1.88.dist-info/METADATA,sha256=sRPgbbeqvtQDaRtne2JRYwt43hrR7oARbtNFlJ-6_7s,3440
15
+ database_wrapper-0.1.88.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
16
+ database_wrapper-0.1.88.dist-info/top_level.txt,sha256=QcnS4ocJygxcKE5eoOqriuja306oVu-zJRn6yjRRhBw,17
17
+ database_wrapper-0.1.88.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.3.1)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5