mysqlengine 1.0.0__cp311-cp311-macosx_10_9_universal2.whl → 1.0.1__cp311-cp311-macosx_10_9_universal2.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.
Potentially problematic release.
This version of mysqlengine might be problematic. Click here for more details.
- mysqlengine/column.c +104 -38
- mysqlengine/column.cpython-311-darwin.so +0 -0
- mysqlengine/constraint.c +104 -38
- mysqlengine/constraint.cpython-311-darwin.so +0 -0
- mysqlengine/database.c +104 -38
- mysqlengine/database.cpython-311-darwin.so +0 -0
- mysqlengine/dml.c +6686 -6544
- mysqlengine/dml.cpython-311-darwin.so +0 -0
- mysqlengine/dml.py +189 -15
- mysqlengine/element.c +3604 -3525
- mysqlengine/element.cpython-311-darwin.so +0 -0
- mysqlengine/element.py +103 -75
- mysqlengine/index.c +104 -38
- mysqlengine/index.cpython-311-darwin.so +0 -0
- mysqlengine/partition.c +104 -38
- mysqlengine/partition.cpython-311-darwin.so +0 -0
- mysqlengine/table.c +104 -38
- mysqlengine/table.cpython-311-darwin.so +0 -0
- mysqlengine/utils.c +9 -8
- mysqlengine/utils.cpython-311-darwin.so +0 -0
- {mysqlengine-1.0.0.dist-info → mysqlengine-1.0.1.dist-info}/METADATA +2 -2
- mysqlengine-1.0.1.dist-info/RECORD +42 -0
- mysqlengine-1.0.0.dist-info/RECORD +0 -42
- {mysqlengine-1.0.0.dist-info → mysqlengine-1.0.1.dist-info}/WHEEL +0 -0
- {mysqlengine-1.0.0.dist-info → mysqlengine-1.0.1.dist-info}/licenses/LICENSE +0 -0
- {mysqlengine-1.0.0.dist-info → mysqlengine-1.0.1.dist-info}/top_level.txt +0 -0
|
Binary file
|
mysqlengine/element.py
CHANGED
|
@@ -136,19 +136,16 @@ class Element(ObjStr):
|
|
|
136
136
|
# Acquire / Transaction / Fill / Release -----------------------------------------------
|
|
137
137
|
@cython.ccall
|
|
138
138
|
def acquire(self) -> PoolConnectionManager:
|
|
139
|
-
"""Acquire a free connection from the
|
|
140
|
-
through context manager `<'PoolConnectionManager'>`.
|
|
139
|
+
"""Acquire a free connection from the pool through context manager `<'PoolConnectionManager'>`.
|
|
141
140
|
|
|
142
141
|
## Notice
|
|
143
|
-
- On
|
|
144
|
-
|
|
145
|
-
-
|
|
146
|
-
(
|
|
147
|
-
|
|
148
|
-
pool
|
|
149
|
-
|
|
150
|
-
the pool connections consistency. Please call `conn.schedule_close()`
|
|
151
|
-
before releasing the connection back to the pool.
|
|
142
|
+
- **On Acquisition**: The following session settings are reset to the pool's defaults:
|
|
143
|
+
`autocommit`, `used_decimal`, `decode_bit`, `decode_json`.
|
|
144
|
+
- **At Release**: Any changes made vis `set_*()` methods (e.g. `set_charset()`,
|
|
145
|
+
`set_read_timeout()`, etc.) will be reverted back to the pool defaults.
|
|
146
|
+
- **Consistency**: Any other session-level changes (e.g. via SQL statements) will
|
|
147
|
+
break the pool connection consistency. Please call `Connection.schedule_close()`
|
|
148
|
+
before exiting the context.
|
|
152
149
|
|
|
153
150
|
## Example (sync):
|
|
154
151
|
>>> with element.acquire() as conn:
|
|
@@ -164,38 +161,30 @@ class Element(ObjStr):
|
|
|
164
161
|
|
|
165
162
|
@cython.ccall
|
|
166
163
|
def transaction(self) -> PoolTransactionManager:
|
|
167
|
-
"""Acquire a free connection from the
|
|
168
|
-
|
|
164
|
+
"""Acquire a free connection from the pool in TRANSACTION mode
|
|
165
|
+
through context manager `<'PoolTransactionManager'>`.
|
|
169
166
|
|
|
170
|
-
##
|
|
171
|
-
By acquiring connection through this method, the following happens:
|
|
167
|
+
## On enter
|
|
172
168
|
- 1. Acquire a free connection from the pool.
|
|
173
|
-
- 2.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
-
|
|
178
|
-
the connection when release back to the pool.
|
|
169
|
+
- 2. Calls `BEGIN` on the connection
|
|
170
|
+
|
|
171
|
+
## On exit
|
|
172
|
+
- If no exception occurs: calls `COMMIT` and releases the connection back to the pool for reuse.
|
|
173
|
+
- If an exception occurs: Schedules the connection for closure and releases it back to the pool.
|
|
179
174
|
|
|
180
175
|
## Notice
|
|
181
|
-
- On
|
|
182
|
-
|
|
183
|
-
-
|
|
184
|
-
(
|
|
185
|
-
|
|
186
|
-
pool
|
|
187
|
-
|
|
188
|
-
the pool connections consistency. Please call `conn.schedule_close()`
|
|
189
|
-
before releasing the connection back to the pool.
|
|
176
|
+
- **On Acquisition**: The following session settings are reset to the pool's defaults:
|
|
177
|
+
`autocommit`, `used_decimal`, `decode_bit`, `decode_json`.
|
|
178
|
+
- **At Release**: Any changes made vis `set_*()` methods (e.g. `set_charset()`,
|
|
179
|
+
`set_read_timeout()`, etc.) will be reverted back to the pool defaults.
|
|
180
|
+
- **Consistency**: Any other session-level changes (e.g. via SQL statements) will
|
|
181
|
+
break the pool connection consistency. Please call `Connection.schedule_close()`
|
|
182
|
+
before exiting the context.
|
|
190
183
|
|
|
191
184
|
## Example (sync):
|
|
192
185
|
>>> with element.transaction() as conn:
|
|
193
186
|
with conn.cursor() as cur:
|
|
194
187
|
cur.execute("INSERT INTO tb (id, name) VALUES (1, 'test')")
|
|
195
|
-
# Equivalent to:
|
|
196
|
-
BEGIN;
|
|
197
|
-
INSERT INTO tb (id, name) VALUES (1, 'test');
|
|
198
|
-
COMMIT;
|
|
199
188
|
|
|
200
189
|
## Example (async):
|
|
201
190
|
>>> async with element.transaction() as conn:
|
|
@@ -209,36 +198,39 @@ class Element(ObjStr):
|
|
|
209
198
|
return self._pool.transaction()
|
|
210
199
|
|
|
211
200
|
async def fill(self, num: int = 1) -> None:
|
|
212
|
-
"""Fill the pool with new
|
|
201
|
+
"""Fill the pool with new [async] connections.
|
|
213
202
|
|
|
214
203
|
:param num `<'int'>`: Number of new [async] connections to create. Defaults to `1`.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
204
|
+
|
|
205
|
+
- If 'num' plus the total [async] connections in the pool exceeds the
|
|
206
|
+
maximum pool size, only fills up to the `Pool.max_size` limit.
|
|
207
|
+
- If 'num=-1', fills up to the `Pool.min_size` limit.
|
|
218
208
|
"""
|
|
219
209
|
return await self._pool.fill(num)
|
|
220
210
|
|
|
221
211
|
@cython.ccall
|
|
222
212
|
def release(self, conn: PoolConnection | PoolSyncConnection) -> object:
|
|
223
|
-
"""Release a connection back to the pool `<'
|
|
213
|
+
"""Release a connection back to the pool `<'Task[None]'>`.
|
|
224
214
|
|
|
225
|
-
Use this method
|
|
226
|
-
obtained via
|
|
227
|
-
by their context managers.
|
|
215
|
+
- Use this method `ONLY` when you directly acquired a connection without the context manager.
|
|
216
|
+
- Connections obtained via context manager are released automatically on exits.
|
|
228
217
|
|
|
229
218
|
:param conn `<'PoolConnection/PoolSyncConnection'>`: The pool [sync/async] connection to release.
|
|
230
|
-
:raises `<'PoolReleaseError'>`: If the connection does not belong to the connection pool.
|
|
231
219
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
220
|
+
:returns `<'Task[None]'>`: An `asyncio.Task` that resolves once the connection is released.
|
|
221
|
+
|
|
222
|
+
- For a [sync] connection, the returned `Task` can be ignored,
|
|
223
|
+
as the connection is released immediately.
|
|
224
|
+
- For an [async] connection, the returned `Task` must be awaited
|
|
225
|
+
to ensure the connection is properly handled.
|
|
226
|
+
|
|
227
|
+
:raises `<'PoolReleaseError'>`: If the connection does not belong to the pool.
|
|
228
|
+
|
|
229
|
+
## Example (sync):
|
|
230
|
+
>>> element.release(sync_conn) # immediate release
|
|
231
|
+
|
|
232
|
+
## Example (async):
|
|
233
|
+
>>> await element.release(async_conn) # 'await' for release
|
|
242
234
|
"""
|
|
243
235
|
return self._pool.release(conn)
|
|
244
236
|
|
|
@@ -974,18 +966,38 @@ class Element(ObjStr):
|
|
|
974
966
|
# Utils --------------------------------------------------------------------------------
|
|
975
967
|
@cython.cfunc
|
|
976
968
|
@cython.inline(True)
|
|
977
|
-
def _escape_args(self, args: object
|
|
978
|
-
"""(internal)
|
|
979
|
-
|
|
980
|
-
:param args `<'
|
|
981
|
-
|
|
982
|
-
- **
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
969
|
+
def _escape_args(self, args: object, itemize: cython.bint = True) -> object:
|
|
970
|
+
"""(internal) Prepare and escape arguments for SQL binding `<'str/tuple/list[str/tuple]'>`.
|
|
971
|
+
|
|
972
|
+
:param args `<'Any'>`: Arguments to escape, supports:
|
|
973
|
+
|
|
974
|
+
- **Python built-ins**:
|
|
975
|
+
int, float, bool, str, None, datetime, date, time,
|
|
976
|
+
timedelta, struct_time, bytes, bytearray, memoryview,
|
|
977
|
+
Decimal, dict, list, tuple, set, frozenset, range
|
|
978
|
+
- **Library [numpy](https://github.com/numpy/numpy)**:
|
|
979
|
+
np.int, np.uint, np.float, np.bool, np.bytes,
|
|
980
|
+
np.str, np.datetime64, np.timedelta64, np.ndarray
|
|
981
|
+
- **Library [pandas](https://github.com/pandas-dev/pandas)**:
|
|
982
|
+
pd.Timestamp, pd.Timedelta, pd.DatetimeIndex,
|
|
983
|
+
pd.TimedeltaIndex, pd.Series, pd.DataFrame
|
|
984
|
+
- **Library [cytimes](https://github.com/AresJef/cyTimes)**:
|
|
985
|
+
cytimes.Pydt, cytimes.Pddt
|
|
986
|
+
|
|
987
|
+
:param itemize `<'bool'>`: Whether to escape items of the 'args' individually. Defaults to `True`.
|
|
988
|
+
- `itemize=False`: Always escapes to one single literal string `<'str'>`, regardless of the 'args' type.
|
|
989
|
+
- `itemize=True`: The 'args' data type determines how escape is done.
|
|
990
|
+
- 1. Sequence or Mapping (e.g. `list`, `tuple`, `dict`, etc) escapes to `<'tuple[str]'>`.
|
|
991
|
+
- 2. `pd.Series` and 1-dimensional `np.ndarray` escapes to `<'tuple[str]'>`.
|
|
992
|
+
- 3. `pd.DataFrame` and 2-dimensional `np.ndarray` escapes to `<'list[tuple[str]]'>`.
|
|
993
|
+
- 4. Single object (such as `int`, `float`, `str`, etc) escapes to one literal string `<'str'>`.
|
|
994
|
+
|
|
995
|
+
:returns `<'str/tuple/list'>`:
|
|
996
|
+
- If returns `<'str'>`, it represents a single literal string.
|
|
997
|
+
- If returns `<'tuple'>`, it represents a single row of literal strings.
|
|
998
|
+
- If returns `<'list'>`, it represents multiple rows of literal strings.
|
|
999
|
+
|
|
1000
|
+
:raises `<'EscapeTypeError'>`: If escape fails due to unsupported type.
|
|
989
1001
|
"""
|
|
990
1002
|
return _escape(args, False, itemize)
|
|
991
1003
|
|
|
@@ -994,21 +1006,37 @@ class Element(ObjStr):
|
|
|
994
1006
|
def _format_sql(
|
|
995
1007
|
self,
|
|
996
1008
|
sql: str,
|
|
997
|
-
args: object
|
|
1009
|
+
args: object,
|
|
998
1010
|
itemize: cython.bint = True,
|
|
999
1011
|
) -> str:
|
|
1000
1012
|
"""(internal) Format the SQL with the given arguments `<'str'>`.
|
|
1001
1013
|
|
|
1002
1014
|
:param sql `<'str'>`: The SQL statement to format.
|
|
1003
|
-
|
|
1004
|
-
:param
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1015
|
+
|
|
1016
|
+
:param args `<'Any'>`: Arguments to escape, supports:
|
|
1017
|
+
|
|
1018
|
+
- **Python built-ins**:
|
|
1019
|
+
int, float, bool, str, None, datetime, date, time,
|
|
1020
|
+
timedelta, struct_time, bytes, bytearray, memoryview,
|
|
1021
|
+
Decimal, dict, list, tuple, set, frozenset, range
|
|
1022
|
+
- **Library [numpy](https://github.com/numpy/numpy)**:
|
|
1023
|
+
np.int, np.uint, np.float, np.bool, np.bytes,
|
|
1024
|
+
np.str, np.datetime64, np.timedelta64, np.ndarray
|
|
1025
|
+
- **Library [pandas](https://github.com/pandas-dev/pandas)**:
|
|
1026
|
+
pd.Timestamp, pd.Timedelta, pd.DatetimeIndex,
|
|
1027
|
+
pd.TimedeltaIndex, pd.Series, pd.DataFrame
|
|
1028
|
+
- **Library [cytimes](https://github.com/AresJef/cyTimes)**:
|
|
1029
|
+
cytimes.Pydt, cytimes.Pddt
|
|
1030
|
+
|
|
1031
|
+
:param itemize `<'bool'>`: Whether to escape items of the 'args' individually. Defaults to `True`.
|
|
1032
|
+
- `itemize=False`: Always escapes to one single literal string `<'str'>`, regardless of the 'args' type.
|
|
1033
|
+
- `itemize=True`: The 'args' data type determines how escape is done.
|
|
1034
|
+
- 1. Sequence or Mapping (e.g. `list`, `tuple`, `dict`, etc) escapes to `<'tuple[str]'>`.
|
|
1035
|
+
- 2. `pd.Series` and 1-dimensional `np.ndarray` escapes to `<'tuple[str]'>`.
|
|
1036
|
+
- 3. `pd.DataFrame` and 2-dimensional `np.ndarray` escapes to `<'list[tuple[str]]'>`.
|
|
1037
|
+
- 4. Single object (such as `int`, `float`, `str`, etc) escapes to one literal string `<'str'>`.
|
|
1038
|
+
|
|
1039
|
+
:returns `<'str'>`: The SQL statement formatted with escaped arguments.
|
|
1012
1040
|
"""
|
|
1013
1041
|
if args is None:
|
|
1014
1042
|
return sql # exit
|