mysqlengine 1.0.0__cp311-cp311-win_amd64.whl → 1.0.3__cp311-cp311-win_amd64.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/__init__.pxd +0 -0
- mysqlengine/column.c +104 -38
- mysqlengine/column.cp311-win_amd64.pyd +0 -0
- mysqlengine/column.pxd +149 -0
- mysqlengine/constraint.c +104 -38
- mysqlengine/constraint.cp311-win_amd64.pyd +0 -0
- mysqlengine/constraint.pxd +121 -0
- mysqlengine/database.c +104 -38
- mysqlengine/database.cp311-win_amd64.pyd +0 -0
- mysqlengine/database.pxd +58 -0
- mysqlengine/dml.c +6686 -6544
- mysqlengine/dml.cp311-win_amd64.pyd +0 -0
- mysqlengine/dml.pxd +387 -0
- mysqlengine/dml.py +189 -15
- mysqlengine/element.c +3604 -3525
- mysqlengine/element.cp311-win_amd64.pyd +0 -0
- mysqlengine/element.pxd +179 -0
- mysqlengine/element.py +103 -75
- mysqlengine/index.c +104 -38
- mysqlengine/index.cp311-win_amd64.pyd +0 -0
- mysqlengine/index.pxd +71 -0
- mysqlengine/partition.c +104 -38
- mysqlengine/partition.cp311-win_amd64.pyd +0 -0
- mysqlengine/partition.pxd +128 -0
- mysqlengine/table.c +104 -38
- mysqlengine/table.cp311-win_amd64.pyd +0 -0
- mysqlengine/table.pxd +169 -0
- mysqlengine/utils.c +9 -8
- mysqlengine/utils.cp311-win_amd64.pyd +0 -0
- mysqlengine/utils.pxd +613 -0
- {mysqlengine-1.0.0.dist-info → mysqlengine-1.0.3.dist-info}/METADATA +3 -4
- mysqlengine-1.0.3.dist-info/RECORD +52 -0
- mysqlengine-1.0.0.dist-info/RECORD +0 -42
- {mysqlengine-1.0.0.dist-info → mysqlengine-1.0.3.dist-info}/WHEEL +0 -0
- {mysqlengine-1.0.0.dist-info → mysqlengine-1.0.3.dist-info}/licenses/LICENSE +0 -0
- {mysqlengine-1.0.0.dist-info → mysqlengine-1.0.3.dist-info}/top_level.txt +0 -0
|
Binary file
|
mysqlengine/element.pxd
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# cython: language_level=3
|
|
2
|
+
from sqlcycli.sqlfunc cimport ObjStr
|
|
3
|
+
from sqlcycli.charset cimport Charset
|
|
4
|
+
from sqlcycli.connection cimport Cursor
|
|
5
|
+
from sqlcycli.aio.pool cimport (
|
|
6
|
+
Pool,
|
|
7
|
+
PoolSyncConnection,
|
|
8
|
+
PoolConnectionManager,
|
|
9
|
+
PoolTransactionManager,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
# Element
|
|
13
|
+
cdef class Element(ObjStr):
|
|
14
|
+
cdef:
|
|
15
|
+
# . internal
|
|
16
|
+
str _el_cate
|
|
17
|
+
str _el_type
|
|
18
|
+
str _el_repr
|
|
19
|
+
int _el_position
|
|
20
|
+
bint _el_ready
|
|
21
|
+
bint _initialized
|
|
22
|
+
Py_ssize_t _hashcode
|
|
23
|
+
# . settings
|
|
24
|
+
str _name
|
|
25
|
+
str _symbol
|
|
26
|
+
str _tb_name
|
|
27
|
+
str _db_name
|
|
28
|
+
str _tb_qualified_name
|
|
29
|
+
Charset _charset
|
|
30
|
+
Pool _pool
|
|
31
|
+
# Acquire / Fill / Release
|
|
32
|
+
cpdef PoolConnectionManager acquire(self)
|
|
33
|
+
cpdef PoolTransactionManager transaction(self)
|
|
34
|
+
cpdef object release(self, object conn)
|
|
35
|
+
# Sync
|
|
36
|
+
cpdef tuple ShowDatabases(self)
|
|
37
|
+
cpdef str ShowCreateTable(self)
|
|
38
|
+
cpdef PoolSyncConnection Unlock(self, PoolSyncConnection conn)
|
|
39
|
+
# SQL
|
|
40
|
+
cpdef str _gen_show_create_table_sql(self)
|
|
41
|
+
# Setter
|
|
42
|
+
cpdef bint _set_el_type(self, str el_type) except -1
|
|
43
|
+
cpdef bint set_name(self, object name) except -1
|
|
44
|
+
cpdef bint _set_tb_name(self, object name) except -1
|
|
45
|
+
cpdef bint _set_db_name(self, object name) except -1
|
|
46
|
+
cpdef bint _set_tb_qualified_name(self) except -1
|
|
47
|
+
cpdef bint _set_charset(self, object charset=?, object collate=?) except -1
|
|
48
|
+
cpdef bint _set_pool(self, object pool) except -1
|
|
49
|
+
cpdef bint _set_position(self, int position) except -1
|
|
50
|
+
# Assure Ready
|
|
51
|
+
cpdef bint _assure_ready(self) except -1
|
|
52
|
+
cdef inline bint _assure_name_ready(self) except -1
|
|
53
|
+
cdef inline bint _assure_tb_name_ready(self) except -1
|
|
54
|
+
cdef inline bint _assure_db_name_ready(self) except -1
|
|
55
|
+
cdef inline bint _assure_charset_ready(self) except -1
|
|
56
|
+
cdef inline bint _assure_pool_ready(self) except -1
|
|
57
|
+
cdef inline bint _assure_encoding_ready(self) except -1
|
|
58
|
+
cdef inline bint _assure_position_ready(self) except -1
|
|
59
|
+
# Validate
|
|
60
|
+
cdef inline str _validate_database_name(self, object name)
|
|
61
|
+
cdef inline str _validate_table_name(self, object name)
|
|
62
|
+
cdef inline str _validate_column_name(self, object name)
|
|
63
|
+
cdef inline str _validete_index_name(self, object name)
|
|
64
|
+
cdef inline str _validate_constraint_name(self, object name)
|
|
65
|
+
cdef inline str _validate_partition_name(self, object name)
|
|
66
|
+
cdef inline tuple _validate_columns(self, object columns)
|
|
67
|
+
cdef inline Pool _validate_pool(self, object pool)
|
|
68
|
+
cdef inline Charset _validate_charset(self, object charset=?, object collate=?)
|
|
69
|
+
cdef inline Charset _validate_encoding(self, Charset charset)
|
|
70
|
+
cdef inline str _validate_index_type(self, object row_format)
|
|
71
|
+
cdef inline str _validate_comment(self, object comment)
|
|
72
|
+
cdef inline str _validate_expression(self, object expr)
|
|
73
|
+
cdef inline int _validate_encryption(self, object encryption) except -2
|
|
74
|
+
# Error
|
|
75
|
+
cdef inline bint _raise_element_error(self, str err_type, str msg, Exception tb_exc=?) except -1
|
|
76
|
+
cdef inline bint _raise_definition_error(self, str msg, Exception tb_exc=?) except -1
|
|
77
|
+
cdef inline bint _raise_argument_error(self, str msg, Exception tb_exc=?) except -1
|
|
78
|
+
cdef inline bint _raise_metadata_error(self, str msg, Exception tb_exc=?) except -1
|
|
79
|
+
cdef inline bint _raise_not_exists_error(self, str msg, Exception tb_exc=?) except -1
|
|
80
|
+
cdef inline bint _raise_critical_error(self, str msg, Exception tb_exc=?) except -1
|
|
81
|
+
cdef inline bint _raise_operational_error(self, object errno, str msg, Exception tb_exc=?) except -1
|
|
82
|
+
cdef inline bint _raise_not_implemented_error(self, str method_name) except -1
|
|
83
|
+
cdef inline str _prep_error_message(self, str msg)
|
|
84
|
+
# Warning
|
|
85
|
+
cdef inline bint _warn(self, str msg) except -1
|
|
86
|
+
# Internal
|
|
87
|
+
cpdef bint _set_initialized(self, bint flag) except -1
|
|
88
|
+
# Utils
|
|
89
|
+
cdef inline object _escape_args(self, object args, bint itemize=?)
|
|
90
|
+
cdef inline str _format_sql(self, str sql, object args, bint itemize=?)
|
|
91
|
+
cdef inline str _gen_tb_qualified_name(self, str name)
|
|
92
|
+
cdef inline tuple _flatten_rows(self, tuple rows, bint skip_none=?)
|
|
93
|
+
cdef inline str _partitioning_flag_to_method(self, int flag)
|
|
94
|
+
cdef inline int _partitioning_method_to_flag(self, str method) except -1
|
|
95
|
+
# Copy
|
|
96
|
+
cpdef Element copy(self)
|
|
97
|
+
# Special Methods
|
|
98
|
+
cpdef Py_ssize_t _sp_hashcode(self)
|
|
99
|
+
cpdef int _sp_equal(self, object o) except -2
|
|
100
|
+
cpdef int _sp_less_than(self, object o) except -2
|
|
101
|
+
|
|
102
|
+
# Elements
|
|
103
|
+
cdef class Elements(Element):
|
|
104
|
+
cdef:
|
|
105
|
+
object _el_class
|
|
106
|
+
dict _el_dict
|
|
107
|
+
set _el_set
|
|
108
|
+
Py_ssize_t _size
|
|
109
|
+
# Collection
|
|
110
|
+
cpdef bint add(self, object element) except -1
|
|
111
|
+
cpdef bint remove(self, object name) except -1
|
|
112
|
+
cpdef Elements _search_name(self, object names, bint exact)
|
|
113
|
+
cpdef Elements _search_type(self, object types, bint exact)
|
|
114
|
+
cpdef Elements _filter(self, object elements)
|
|
115
|
+
cpdef bint _issubset(self, object elements) except -1
|
|
116
|
+
# Generate SQL
|
|
117
|
+
cpdef str _gen_definition_sql(self, int indent=?)
|
|
118
|
+
# Assure Ready
|
|
119
|
+
cpdef bint _assure_ready(self) except -1
|
|
120
|
+
# Validate
|
|
121
|
+
cdef inline list _validate_elements(self, object elements)
|
|
122
|
+
# Utils
|
|
123
|
+
cdef inline set _extract_elements(self, object elements, str msg)
|
|
124
|
+
cdef inline set _extract_element_names(self, object elements, str msg)
|
|
125
|
+
cdef inline set _extract_element_types(self, object elements, str msg)
|
|
126
|
+
# Accessors
|
|
127
|
+
cpdef tuple keys(self)
|
|
128
|
+
cpdef tuple values(self)
|
|
129
|
+
cpdef tuple items(self)
|
|
130
|
+
cpdef object get(self, object key, object default=?)
|
|
131
|
+
cdef inline list _sorted_elements(self)
|
|
132
|
+
|
|
133
|
+
# Metadata
|
|
134
|
+
cdef class Metadata:
|
|
135
|
+
cdef:
|
|
136
|
+
str _el_cate
|
|
137
|
+
dict _meta
|
|
138
|
+
int _size
|
|
139
|
+
Py_ssize_t _hashcode
|
|
140
|
+
# Error
|
|
141
|
+
cdef inline bint _raise_invalid_metadata_error(self, object meta, Exception tb_exc=?) except -1
|
|
142
|
+
# Accessors
|
|
143
|
+
cpdef tuple keys(self)
|
|
144
|
+
cpdef tuple values(self)
|
|
145
|
+
cpdef tuple items(self)
|
|
146
|
+
cpdef object get(self, str key, object default=?)
|
|
147
|
+
|
|
148
|
+
# Query
|
|
149
|
+
cdef class Query:
|
|
150
|
+
cdef:
|
|
151
|
+
Logs _logs
|
|
152
|
+
str _sql1
|
|
153
|
+
str _sql2
|
|
154
|
+
# Execute
|
|
155
|
+
cpdef bint executable(self) except -1
|
|
156
|
+
cpdef bint execute(self, Cursor cur) except -1
|
|
157
|
+
# Setter
|
|
158
|
+
cpdef bint set_sql(self, Element element, str sql) except -1
|
|
159
|
+
|
|
160
|
+
# Logs
|
|
161
|
+
cdef class Logs:
|
|
162
|
+
cdef:
|
|
163
|
+
list _records
|
|
164
|
+
bint _skip_flag
|
|
165
|
+
Py_ssize_t _size
|
|
166
|
+
# Logging
|
|
167
|
+
cpdef Logs log(self, Element element, bint local, str msg)
|
|
168
|
+
cpdef Logs log_element_creation(self, Element element, bint local)
|
|
169
|
+
cpdef Logs log_element_deletion(self, Element element, bint local)
|
|
170
|
+
cpdef Logs log_sql(self, Element element, str sql)
|
|
171
|
+
cpdef Logs log_charset(self, Element element, Charset config_old, Charset config_new)
|
|
172
|
+
cpdef Logs log_config_bool(self, Element element, str config_name, int config_old, int config_new)
|
|
173
|
+
cpdef Logs log_config_int(self, Element element, str config_name, long long config_old, long long config_new)
|
|
174
|
+
cpdef Logs log_config_obj(self, Element element, str config_name, object config_old, object config_new)
|
|
175
|
+
cpdef Logs log_sync_failed_not_exist(self, Element element)
|
|
176
|
+
cpdef Logs log_sync_failed_mismatch(self, Element element, str config_name, object config_local, object config_remote)
|
|
177
|
+
# Manipulate
|
|
178
|
+
cpdef Logs extend(self, Logs logs)
|
|
179
|
+
cpdef Logs _skip(self)
|
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
|