ormlambda 2.6.0__py3-none-any.whl → 2.6.1__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.
- ormlambda/common/interfaces/IRepositoryBase.py +1 -10
- ormlambda/databases/my_sql/repository.py +27 -45
- {ormlambda-2.6.0.dist-info → ormlambda-2.6.1.dist-info}/METADATA +1 -1
- {ormlambda-2.6.0.dist-info → ormlambda-2.6.1.dist-info}/RECORD +6 -6
- {ormlambda-2.6.0.dist-info → ormlambda-2.6.1.dist-info}/LICENSE +0 -0
- {ormlambda-2.6.0.dist-info → ormlambda-2.6.1.dist-info}/WHEEL +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
from abc import ABC, abstractmethod
|
2
|
-
from typing import
|
2
|
+
from typing import Literal, Optional, Type
|
3
3
|
|
4
4
|
TypeExists = Literal["fail", "replace", "append"]
|
5
5
|
|
@@ -8,15 +8,6 @@ class IRepositoryBase[T](ABC):
|
|
8
8
|
def __repr__(self) -> str:
|
9
9
|
return f"{IRepositoryBase.__name__}: {self.__class__.__name__}"
|
10
10
|
|
11
|
-
@abstractmethod
|
12
|
-
def is_connected(self) -> bool: ...
|
13
|
-
|
14
|
-
@abstractmethod
|
15
|
-
def connect(self, **kwargs: Any) -> None: ...
|
16
|
-
|
17
|
-
@abstractmethod
|
18
|
-
def close_connection(self) -> None: ...
|
19
|
-
|
20
11
|
@abstractmethod
|
21
12
|
def read_sql[TFlavour](self, query: str, flavour: Optional[Type[TFlavour]], **kwargs) -> tuple[TFlavour]: ...
|
22
13
|
|
@@ -77,45 +77,27 @@ class Response[TFlavour, *Ts]:
|
|
77
77
|
class MySQLRepository(IRepositoryBase[MySQLConnection]):
|
78
78
|
def get_connection(func: Callable[..., Any]):
|
79
79
|
@functools.wraps(func)
|
80
|
-
def wrapper(self:
|
81
|
-
self.
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
self.close_connection()
|
89
|
-
return foo
|
80
|
+
def wrapper(self: MySQLRepository, *args, **kwargs):
|
81
|
+
with self._pool.get_connection() as cnx:
|
82
|
+
try:
|
83
|
+
foo = func(self, cnx, *args, **kwargs)
|
84
|
+
return foo
|
85
|
+
except Exception as e:
|
86
|
+
self.connection.rollback()
|
87
|
+
raise e
|
90
88
|
|
91
89
|
return wrapper
|
92
90
|
|
93
91
|
def __init__(self, **kwargs: Any) -> None:
|
94
92
|
self._data_config: dict[str, Any] = kwargs
|
95
93
|
self._pool: MySQLConnectionPool = self.__create_MySQLConnectionPool()
|
96
|
-
self._connection: PooledMySQLConnection = None
|
97
94
|
|
98
95
|
def __create_MySQLConnectionPool(self):
|
99
96
|
return MySQLConnectionPool(pool_name="mypool", pool_size=10, **self._data_config)
|
100
97
|
|
101
|
-
@override
|
102
|
-
def is_connected(self) -> bool:
|
103
|
-
return self._connection._cnx is not None if self._connection else False
|
104
|
-
|
105
|
-
@override
|
106
|
-
def connect(self) -> None:
|
107
|
-
self._connection = self._pool.get_connection()
|
108
|
-
return None
|
109
|
-
|
110
|
-
@override
|
111
|
-
def close_connection(self) -> None:
|
112
|
-
if self.is_connected():
|
113
|
-
self._connection.close()
|
114
|
-
return None
|
115
|
-
|
116
98
|
@override
|
117
99
|
@get_connection
|
118
|
-
def read_sql[TFlavour](self, query: str, flavour: Type[TFlavour] = tuple, **kwargs) -> tuple[TFlavour]:
|
100
|
+
def read_sql[TFlavour](self, cnx: MySQLConnection, query: str, flavour: Type[TFlavour] = tuple, **kwargs) -> tuple[TFlavour]:
|
119
101
|
"""
|
120
102
|
Return tuple of tuples by default.
|
121
103
|
|
@@ -125,7 +107,7 @@ class MySQLRepository(IRepositoryBase[MySQLConnection]):
|
|
125
107
|
- flavour: Type[TFlavour]: Useful to return tuple of any Iterable type as dict,set,list...
|
126
108
|
"""
|
127
109
|
|
128
|
-
with
|
110
|
+
with cnx.cursor(buffered=True) as cursor:
|
129
111
|
cursor.execute(query)
|
130
112
|
values: list[tuple] = cursor.fetchall()
|
131
113
|
columns: tuple[str] = cursor.column_names
|
@@ -133,7 +115,7 @@ class MySQLRepository(IRepositoryBase[MySQLConnection]):
|
|
133
115
|
|
134
116
|
# FIXME [ ]: this method does not comply with the implemented interface
|
135
117
|
@get_connection
|
136
|
-
def create_tables_code_first(self, path: str | Path) -> None:
|
118
|
+
def create_tables_code_first(self, cnx: MySQLConnection, path: str | Path) -> None:
|
137
119
|
if not isinstance(path, Path | str):
|
138
120
|
raise ValueError
|
139
121
|
|
@@ -148,33 +130,33 @@ class MySQLRepository(IRepositoryBase[MySQLConnection]):
|
|
148
130
|
queries_list: list[str] = module_tree.get_queries()
|
149
131
|
|
150
132
|
for query in queries_list:
|
151
|
-
with
|
133
|
+
with cnx.cursor(buffered=True) as cursor:
|
152
134
|
cursor.execute(query)
|
153
|
-
|
135
|
+
cnx.commit()
|
154
136
|
return None
|
155
137
|
|
156
138
|
@override
|
157
139
|
@get_connection
|
158
|
-
def executemany_with_values(self, query: str, values) -> None:
|
159
|
-
with
|
140
|
+
def executemany_with_values(self, cnx: MySQLConnection, query: str, values) -> None:
|
141
|
+
with cnx.cursor(buffered=True) as cursor:
|
160
142
|
cursor.executemany(query, values)
|
161
|
-
|
143
|
+
cnx.commit()
|
162
144
|
return None
|
163
145
|
|
164
146
|
@override
|
165
147
|
@get_connection
|
166
|
-
def execute_with_values(self, query: str, values) -> None:
|
167
|
-
with
|
148
|
+
def execute_with_values(self, cnx: MySQLConnection, query: str, values) -> None:
|
149
|
+
with cnx.cursor(buffered=True) as cursor:
|
168
150
|
cursor.execute(query, values)
|
169
|
-
|
151
|
+
cnx.commit()
|
170
152
|
return None
|
171
153
|
|
172
154
|
@override
|
173
155
|
@get_connection
|
174
|
-
def execute(self, query: str) -> None:
|
175
|
-
with
|
156
|
+
def execute(self, cnx: MySQLConnection, query: str) -> None:
|
157
|
+
with cnx.cursor(buffered=True) as cursor:
|
176
158
|
cursor.execute(query)
|
177
|
-
|
159
|
+
cnx.commit()
|
178
160
|
return None
|
179
161
|
|
180
162
|
@override
|
@@ -183,9 +165,9 @@ class MySQLRepository(IRepositoryBase[MySQLConnection]):
|
|
183
165
|
|
184
166
|
@override
|
185
167
|
@get_connection
|
186
|
-
def database_exists(self, name: str) -> bool:
|
168
|
+
def database_exists(self, cnx: MySQLConnection, name: str) -> bool:
|
187
169
|
query = "SHOW DATABASES LIKE %s;"
|
188
|
-
with
|
170
|
+
with cnx.cursor(buffered=True) as cursor:
|
189
171
|
cursor.execute(query, (name,))
|
190
172
|
res = cursor.fetchmany(1)
|
191
173
|
return len(res) > 0
|
@@ -196,12 +178,12 @@ class MySQLRepository(IRepositoryBase[MySQLConnection]):
|
|
196
178
|
|
197
179
|
@override
|
198
180
|
@get_connection
|
199
|
-
def table_exists(self, name: str) -> bool:
|
200
|
-
if not
|
181
|
+
def table_exists(self, cnx: MySQLConnection, name: str) -> bool:
|
182
|
+
if not cnx.database:
|
201
183
|
raise Exception("No database selected")
|
202
184
|
|
203
185
|
query = "SHOW TABLES LIKE %s;"
|
204
|
-
with
|
186
|
+
with cnx.cursor(buffered=True) as cursor:
|
205
187
|
cursor.execute(query, (name,))
|
206
188
|
res = cursor.fetchmany(1)
|
207
189
|
return len(res) > 0
|
@@ -12,7 +12,7 @@ ormlambda/common/interfaces/IAggregate.py,sha256=i9zZIYrstP2oolUYqR-udeQQl7M0NwS
|
|
12
12
|
ormlambda/common/interfaces/IDecompositionQuery.py,sha256=VwZdYhVApNyGrWgqr27mRMOxREMb6Xv-oYtW_0c2D2g,1365
|
13
13
|
ormlambda/common/interfaces/INonQueryCommand.py,sha256=7CjLW4sKqkR5zUIGvhRXOtzTs6vypJW1a9EJHlgCw2c,260
|
14
14
|
ormlambda/common/interfaces/IQueryCommand.py,sha256=hfzCosK4-n8RJIb2PYs8b0qU3TNmfYluZXBf47KxxKs,331
|
15
|
-
ormlambda/common/interfaces/IRepositoryBase.py,sha256=
|
15
|
+
ormlambda/common/interfaces/IRepositoryBase.py,sha256=jIwQ6c_eadf3K7dyvBf88kTIb6AqIsIYBc2aJ90RS0I,1196
|
16
16
|
ormlambda/common/interfaces/IStatements.py,sha256=zsjR6JnQ57M6GPGRqAXkuuwZx6fh3Mq6NB4D6gWw-3w,10028
|
17
17
|
ormlambda/common/interfaces/__init__.py,sha256=00ca9a-u_A8DzyEyxPfBMxfqLKFzzUgJaeNmoRitAbA,360
|
18
18
|
ormlambda/components/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -51,7 +51,7 @@ ormlambda/databases/my_sql/functions/__init__.py,sha256=jUFHlFc04UAPht65GlEkLXa5
|
|
51
51
|
ormlambda/databases/my_sql/functions/concat.py,sha256=cZztl5eSATpYMKVKfyPbul6OocaUkaEGpt3uWmhf-3o,1177
|
52
52
|
ormlambda/databases/my_sql/functions/group_by.py,sha256=ym1L6RBA70hmzrkJ-IA_-6Esq7eoVgNdf1vWpqxRq-8,1080
|
53
53
|
ormlambda/databases/my_sql/functions/max.py,sha256=zrO_RBKsHhyokEmSpPI6Yg5OY6Jf4GGp2RveBJdOuuA,1190
|
54
|
-
ormlambda/databases/my_sql/repository.py,sha256=
|
54
|
+
ormlambda/databases/my_sql/repository.py,sha256=KltLdpWFiPaHKFOVcefy3pQ0g_pBFsUVlpBFV7CGEEk,7034
|
55
55
|
ormlambda/databases/my_sql/statements.py,sha256=4o1NguIiNOVA9i8hqaUMJdIfgn1MvXnnJhJABKPJtF0,9660
|
56
56
|
ormlambda/model_base.py,sha256=RrAATQWX_bHJ0ZQ5sCHyJKA4NiR7ZJY4I6dqhnGWWAc,1216
|
57
57
|
ormlambda/utils/__init__.py,sha256=ywMdWqmA2jHj19-W-S04yfaYF5hv4IZ1lZDq0B8Jnjs,142
|
@@ -69,7 +69,7 @@ ormlambda/utils/module_tree/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
69
69
|
ormlambda/utils/module_tree/dfs_traversal.py,sha256=lSF03G63XtJFLp03ueAmsHMBvhUkjptDbK3IugXm8iU,1425
|
70
70
|
ormlambda/utils/module_tree/dynamic_module.py,sha256=zwvjU3U2cz6H2CDp9Gncs5D5bSAyfITNa2SDqFDl8rw,8551
|
71
71
|
ormlambda/utils/table_constructor.py,sha256=8Apm44K6MiYMK3PQyK74MUV18OatbFI9eDLAVklQO0w,11660
|
72
|
-
ormlambda-2.6.
|
73
|
-
ormlambda-2.6.
|
74
|
-
ormlambda-2.6.
|
75
|
-
ormlambda-2.6.
|
72
|
+
ormlambda-2.6.1.dist-info/LICENSE,sha256=xBprFw8GJLdHMOoUqDk0427EvjIcbEREvXXVFULuuXU,1080
|
73
|
+
ormlambda-2.6.1.dist-info/METADATA,sha256=OUhV3mP2xqwH75LftvCqJis1Kmx00sBUnazCPG5DrOQ,8428
|
74
|
+
ormlambda-2.6.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
75
|
+
ormlambda-2.6.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|