mysqlengine 1.0.1__cp313-cp313-macosx_10_13_universal2.whl → 1.0.3__cp313-cp313-macosx_10_13_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/__init__.pxd +0 -0
- mysqlengine/column.c +1 -1
- mysqlengine/column.cpython-313-darwin.so +0 -0
- mysqlengine/column.pxd +149 -0
- mysqlengine/constraint.c +1 -1
- mysqlengine/constraint.cpython-313-darwin.so +0 -0
- mysqlengine/constraint.pxd +121 -0
- mysqlengine/database.c +1 -1
- mysqlengine/database.cpython-313-darwin.so +0 -0
- mysqlengine/database.pxd +58 -0
- mysqlengine/dml.c +148 -148
- mysqlengine/dml.cpython-313-darwin.so +0 -0
- mysqlengine/dml.pxd +387 -0
- mysqlengine/element.c +148 -148
- mysqlengine/element.cpython-313-darwin.so +0 -0
- mysqlengine/element.pxd +179 -0
- mysqlengine/index.c +1 -1
- mysqlengine/index.cpython-313-darwin.so +0 -0
- mysqlengine/index.pxd +71 -0
- mysqlengine/partition.c +1 -1
- mysqlengine/partition.cpython-313-darwin.so +0 -0
- mysqlengine/partition.pxd +128 -0
- mysqlengine/table.c +1 -1
- mysqlengine/table.cpython-313-darwin.so +0 -0
- mysqlengine/table.pxd +169 -0
- mysqlengine/utils.cpython-313-darwin.so +0 -0
- mysqlengine/utils.pxd +613 -0
- {mysqlengine-1.0.1.dist-info → mysqlengine-1.0.3.dist-info}/METADATA +3 -4
- mysqlengine-1.0.3.dist-info/RECORD +52 -0
- mysqlengine-1.0.1.dist-info/RECORD +0 -42
- {mysqlengine-1.0.1.dist-info → mysqlengine-1.0.3.dist-info}/WHEEL +0 -0
- {mysqlengine-1.0.1.dist-info → mysqlengine-1.0.3.dist-info}/licenses/LICENSE +0 -0
- {mysqlengine-1.0.1.dist-info → mysqlengine-1.0.3.dist-info}/top_level.txt +0 -0
mysqlengine/utils.pxd
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
# cython: language_level=3
|
|
2
|
+
from cpython cimport datetime
|
|
3
|
+
from cpython.unicode cimport (
|
|
4
|
+
PyUnicode_Check as is_str,
|
|
5
|
+
PyUnicode_GET_LENGTH as str_len,
|
|
6
|
+
PyUnicode_Substring as str_substr,
|
|
7
|
+
PyUnicode_Contains as str_contains,
|
|
8
|
+
PyUnicode_Tailmatch as str_tailmatch,
|
|
9
|
+
)
|
|
10
|
+
from cpython.set cimport PySet_Contains as set_contains
|
|
11
|
+
from cpython.dict cimport PyDict_GetItem as dict_getitem
|
|
12
|
+
from sqlcycli.charset cimport Charset, _charsets
|
|
13
|
+
from sqlcycli.sqlfunc cimport SQLFunction, RawText
|
|
14
|
+
|
|
15
|
+
# Constant ---------------------------------------------------------------------------------
|
|
16
|
+
cdef:
|
|
17
|
+
#: Base Date (1970-01-01)
|
|
18
|
+
datetime.date BASE_DATE
|
|
19
|
+
#: The MAXVALUE for MySQL partitioning
|
|
20
|
+
RawText MAXVALUE
|
|
21
|
+
#: The MINVALUE (-MAXVALUE) for MySQL partitioning
|
|
22
|
+
RawText MINVALUE
|
|
23
|
+
#: The maximum name length for a MySQL element (Database, Table, Column, Index, etc.)
|
|
24
|
+
int SCHEMA_ELEMENT_MAX_NAME_LENGTH
|
|
25
|
+
# . Options
|
|
26
|
+
#: Acceptable storage engines
|
|
27
|
+
dict STORAGE_ENGINES
|
|
28
|
+
#: Acceptable compression methods
|
|
29
|
+
dict COMPRESSION_METHODS
|
|
30
|
+
#: Acceptable join methods
|
|
31
|
+
dict JOIN_METHODS
|
|
32
|
+
#: Acceptable index hints scopes
|
|
33
|
+
dict INDEX_HINTS_SCOPES
|
|
34
|
+
#: Acceptable insert priorities
|
|
35
|
+
dict INSERT_PRIORITIES
|
|
36
|
+
#: Acceptable time table units
|
|
37
|
+
dict TIMETABLE_UNITS
|
|
38
|
+
#: Acceptable check table options
|
|
39
|
+
set CHECK_TABLE_OPTIONS
|
|
40
|
+
#: Acceptable repair table options
|
|
41
|
+
set REPAIR_TABLE_OPTIONS
|
|
42
|
+
#: Acceptable row formats
|
|
43
|
+
set ROW_FORMATS
|
|
44
|
+
#: Acceptable index types
|
|
45
|
+
set INDEX_TYPES
|
|
46
|
+
#: Acceptable foreign key actions
|
|
47
|
+
set FOREIGN_KEY_ACTIONS
|
|
48
|
+
#: Acceptable locking reads options
|
|
49
|
+
set LOCKING_READS_OPTIONS
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
# Schema Element Settings ------------------------------------------------------------------
|
|
53
|
+
cdef class SchemaElementSettings:
|
|
54
|
+
cdef:
|
|
55
|
+
#: Prohibit names for a MySQL element (Database, Table, Column, Index, etc.)
|
|
56
|
+
set SCHEMA_ELEMENT_PROHIBITED_NAMES
|
|
57
|
+
#: The maximum name length for a MySQL element (Database, Table, Column, Index, etc.)
|
|
58
|
+
int SCHEMA_ELEMENT_MAX_NAME_LENGTH
|
|
59
|
+
cpdef bint add_prohibited_names(self, list names) except -1
|
|
60
|
+
|
|
61
|
+
cdef SchemaElementSettings SCHEMA_ELEMENT_SETTINGS
|
|
62
|
+
|
|
63
|
+
# Validator --------------------------------------------------------------------------------
|
|
64
|
+
cdef inline str _validate_element_name(str element, object name, bint lowercase):
|
|
65
|
+
"""Validate MySQL element name (e.g., 'Database', 'Table', 'Column', 'Index') `<'str'>`
|
|
66
|
+
|
|
67
|
+
:param element `<str'>`: The string representation of the MySQL element.
|
|
68
|
+
:param name `<'object'>`: The name of MySQL element.
|
|
69
|
+
:lowercase `<'bool'>`: Whether to ensure the name is in lowercase.
|
|
70
|
+
"""
|
|
71
|
+
if not is_str(name):
|
|
72
|
+
raise TypeError(
|
|
73
|
+
"%s name must be <'str'> type, instead got %s %r."
|
|
74
|
+
% (element, type(name), name)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
cdef str _name = name
|
|
78
|
+
_name = _name.strip()
|
|
79
|
+
name_lower = _name.lower()
|
|
80
|
+
if set_contains(SCHEMA_ELEMENT_SETTINGS.SCHEMA_ELEMENT_PROHIBITED_NAMES, name_lower):
|
|
81
|
+
raise ValueError(
|
|
82
|
+
"%s name '%s' is prohibited, please choose another one."
|
|
83
|
+
% (element, _name)
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
cdef Py_ssize_t length = str_len(_name)
|
|
87
|
+
if length == 0:
|
|
88
|
+
raise ValueError("%s name cannot be an empty string." % element)
|
|
89
|
+
if length > SCHEMA_ELEMENT_MAX_NAME_LENGTH:
|
|
90
|
+
raise ValueError(
|
|
91
|
+
"%s name cannot exceed %d characters.\nInvalid name: '%s'."
|
|
92
|
+
% (element, SCHEMA_ELEMENT_MAX_NAME_LENGTH, _name)
|
|
93
|
+
)
|
|
94
|
+
return name_lower if lowercase else _name
|
|
95
|
+
|
|
96
|
+
cdef inline str validate_database_name(object name):
|
|
97
|
+
"""Validate MySQL database name `<'str'>`.
|
|
98
|
+
|
|
99
|
+
#### Database name must be a lowercased string with length between 1 and 64.
|
|
100
|
+
"""
|
|
101
|
+
return _validate_element_name("DATABASE", name, True)
|
|
102
|
+
|
|
103
|
+
cdef inline str validate_table_name(object name):
|
|
104
|
+
"""Validate MySQL table name `<'str'>`.
|
|
105
|
+
|
|
106
|
+
#### Table name must be a lowercased string with length between 1 and 64.
|
|
107
|
+
"""
|
|
108
|
+
return _validate_element_name("TABLE", name, True)
|
|
109
|
+
|
|
110
|
+
cdef inline str validate_column_name(object name):
|
|
111
|
+
"""Validate MySQL column name `<'str'>`.
|
|
112
|
+
|
|
113
|
+
#### Column name must be a string with length between 1 and 64.
|
|
114
|
+
"""
|
|
115
|
+
return _validate_element_name("COLUMN", name, False)
|
|
116
|
+
|
|
117
|
+
cdef inline str validete_index_name(object name):
|
|
118
|
+
"""Validate MySQL index name `<'str'>`.
|
|
119
|
+
|
|
120
|
+
#### Index name must be a string with length between 1 and 64.
|
|
121
|
+
"""
|
|
122
|
+
return _validate_element_name("INDEX", name, False)
|
|
123
|
+
|
|
124
|
+
cdef inline str validate_constraint_name(object name):
|
|
125
|
+
"""Validate MySQL constraint name `<'str'>`.
|
|
126
|
+
|
|
127
|
+
#### Constraint name must be a string with length between 1 and 64.
|
|
128
|
+
"""
|
|
129
|
+
return _validate_element_name("CONSTRAINT", name, False)
|
|
130
|
+
|
|
131
|
+
cdef inline str validate_partition_name(object name):
|
|
132
|
+
"""Validate MySQL partition name `<'str'>`.
|
|
133
|
+
|
|
134
|
+
#### Partition name must be a string with length between 1 and 64.
|
|
135
|
+
"""
|
|
136
|
+
return _validate_element_name("PARTITION", name, True)
|
|
137
|
+
|
|
138
|
+
cdef inline Charset validate_charset(object charset=None, object collate=None):
|
|
139
|
+
"""Validate the CHARACTER SET and COLLATE `<'Charset/None'>`
|
|
140
|
+
|
|
141
|
+
:param charset `<'str/Charset/None'>`: The character set. Defaults to `None`.
|
|
142
|
+
:param collate `<'str/None'>`: The collation. Defaults to `None`.
|
|
143
|
+
|
|
144
|
+
#### If both 'charset' and 'collate' are None, returns None.
|
|
145
|
+
"""
|
|
146
|
+
if isinstance(charset, Charset):
|
|
147
|
+
return charset
|
|
148
|
+
|
|
149
|
+
if collate is None:
|
|
150
|
+
if charset is None:
|
|
151
|
+
return None
|
|
152
|
+
return _charsets.by_name(charset)
|
|
153
|
+
|
|
154
|
+
if charset is None:
|
|
155
|
+
return _charsets.by_collation(collate)
|
|
156
|
+
|
|
157
|
+
return _charsets.by_name_n_collation(charset, collate)
|
|
158
|
+
|
|
159
|
+
cdef inline str validate_comment(object comment):
|
|
160
|
+
"""Validate MySQL comment `<'str/None'>`"""
|
|
161
|
+
if comment is None:
|
|
162
|
+
return None
|
|
163
|
+
if not is_str(comment):
|
|
164
|
+
raise TypeError(
|
|
165
|
+
"COMMENT must be <'str/None'> type, instead got %s %r."
|
|
166
|
+
% (type(comment), comment)
|
|
167
|
+
)
|
|
168
|
+
if str_len(comment) == 0:
|
|
169
|
+
return None
|
|
170
|
+
return comment
|
|
171
|
+
|
|
172
|
+
cdef inline str validate_expression(object expr):
|
|
173
|
+
"""Validate MySQL expression `<'str/None'>`"""
|
|
174
|
+
if expr is None:
|
|
175
|
+
return None
|
|
176
|
+
if is_str(expr):
|
|
177
|
+
return cleanup_expression(expr)
|
|
178
|
+
if isinstance(expr, SQLFunction):
|
|
179
|
+
return cleanup_expression(str(expr))
|
|
180
|
+
raise TypeError(
|
|
181
|
+
"EXPRESSION must be <'str/SQLFunction/None'> type, instead got %s %r."
|
|
182
|
+
% (type(expr), expr)
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
cdef inline bint validate_str_contains(str string, str substr) except -1:
|
|
186
|
+
"""Validate if the 'str' value contains the 'substr' `<'bool'>`."""
|
|
187
|
+
return str_contains(string, substr)
|
|
188
|
+
|
|
189
|
+
# . option [bool]
|
|
190
|
+
cdef inline int _validate_bool_config(object config, str config_name) except -2:
|
|
191
|
+
"""Validate MySQL boolean option `<'int'>`
|
|
192
|
+
|
|
193
|
+
### Note:
|
|
194
|
+
- Returns -1 if 'option' is None.
|
|
195
|
+
- Returns 1 if 'option' represents True, else 0.
|
|
196
|
+
"""
|
|
197
|
+
if config is None:
|
|
198
|
+
return -1
|
|
199
|
+
elif isinstance(config, str):
|
|
200
|
+
_opt: str = config
|
|
201
|
+
_opt = _opt.upper()
|
|
202
|
+
if _opt in ("Y", "YES", "TRUE", "ON", "1"):
|
|
203
|
+
return 1
|
|
204
|
+
if _opt in ("N", "NO", "FALSE", "OFF", "0", ""):
|
|
205
|
+
return 0
|
|
206
|
+
else:
|
|
207
|
+
try:
|
|
208
|
+
return bool(config)
|
|
209
|
+
except Exception:
|
|
210
|
+
pass
|
|
211
|
+
|
|
212
|
+
raise ValueError("invalid '%s' option value %r." % (config_name, config))
|
|
213
|
+
|
|
214
|
+
cdef inline int validate_encryption(object encryption) except -2:
|
|
215
|
+
"""Validate MySQL `ENCRYPTION` config `<'int'>.
|
|
216
|
+
|
|
217
|
+
### Note:
|
|
218
|
+
- Returns -1 if 'encryption' is None.
|
|
219
|
+
- Returns 1 if 'encryption' represents True, else 0.
|
|
220
|
+
"""
|
|
221
|
+
return _validate_bool_config(encryption, "encryption")
|
|
222
|
+
|
|
223
|
+
cdef inline int validate_read_only(object read_only) except -2:
|
|
224
|
+
"""Validate MySQL `READ ONLY` config `<'int'>.
|
|
225
|
+
|
|
226
|
+
### Note:
|
|
227
|
+
- Returns -1 if 'read_only' is None.
|
|
228
|
+
- Returns 1 if 'read_only' represents True, else 0.
|
|
229
|
+
"""
|
|
230
|
+
return _validate_bool_config(read_only, "read_only")
|
|
231
|
+
|
|
232
|
+
cdef inline int validate_null(object null) except -2:
|
|
233
|
+
"""Validate MySQL column `NULL` config `<'int'>.
|
|
234
|
+
|
|
235
|
+
### Note:
|
|
236
|
+
- Returns -1 if 'null' is None.
|
|
237
|
+
- Returns 1 if 'null' represents True, else 0.
|
|
238
|
+
"""
|
|
239
|
+
return _validate_bool_config(null, "null")
|
|
240
|
+
|
|
241
|
+
cdef inline int validate_visible(object visible) except -2:
|
|
242
|
+
"""Validate MySQL element `VISIBLE` config `<'int'>.
|
|
243
|
+
|
|
244
|
+
### Note:
|
|
245
|
+
- Returns -1 if 'visible' is None.
|
|
246
|
+
- Returns 1 if 'visible' represents True, else 0.
|
|
247
|
+
"""
|
|
248
|
+
return _validate_bool_config(visible, "visible")
|
|
249
|
+
|
|
250
|
+
cdef inline int validate_enforced(object enforced) except -2:
|
|
251
|
+
"""Validate MySQL element `ENFORCED` config `<'int'>.
|
|
252
|
+
|
|
253
|
+
### Note:
|
|
254
|
+
- Returns -1 if 'enforced' is None.
|
|
255
|
+
- Returns 1 if 'enforced' represents True, else 0.
|
|
256
|
+
"""
|
|
257
|
+
return _validate_bool_config(enforced, "enforced")
|
|
258
|
+
|
|
259
|
+
# . option [dict]
|
|
260
|
+
cdef inline str _validate_dict_option(object option, dict available_options, str option_name):
|
|
261
|
+
"""Validate MySQL option [dict based available options] `<'str/None'>`"""
|
|
262
|
+
if option is None:
|
|
263
|
+
return None
|
|
264
|
+
if not is_str(option):
|
|
265
|
+
raise TypeError(
|
|
266
|
+
"%s must be <'str/None'> type, instead got %s %r."
|
|
267
|
+
% (option_name, type(option), option)
|
|
268
|
+
)
|
|
269
|
+
if str_len(option) == 0:
|
|
270
|
+
return None
|
|
271
|
+
cdef str key = option
|
|
272
|
+
key = key.strip()
|
|
273
|
+
key = key.upper()
|
|
274
|
+
if key in ("DEFAULT", "NONE"):
|
|
275
|
+
return None
|
|
276
|
+
|
|
277
|
+
res = dict_getitem(available_options, key)
|
|
278
|
+
if res is NULL:
|
|
279
|
+
raise ValueError(
|
|
280
|
+
"%s '%s' is invalid, must be one of: %s."
|
|
281
|
+
% (option_name, option, list(available_options.keys()))
|
|
282
|
+
)
|
|
283
|
+
return <str> res
|
|
284
|
+
|
|
285
|
+
cdef inline str validate_engine(object engine):
|
|
286
|
+
"""Validate MySQL storage engine `<'str/None'>`."""
|
|
287
|
+
return _validate_dict_option(
|
|
288
|
+
engine, STORAGE_ENGINES, "STORAGE ENGINE"
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
cdef inline str validate_compression(object compression):
|
|
292
|
+
"""Validate MySQL compression method `<'str/None'>`"""
|
|
293
|
+
return _validate_dict_option(
|
|
294
|
+
compression, COMPRESSION_METHODS, "COMPRESSION"
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
cdef inline str validate_join_method(object join_method):
|
|
298
|
+
"""Validate MySQL join method `<'str/None'>`"""
|
|
299
|
+
return _validate_dict_option(
|
|
300
|
+
join_method, JOIN_METHODS, "JOIN method"
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
cdef inline str validate_index_hints_scope(object scope):
|
|
304
|
+
"""Validate MySQL index hints scope `<'str/None'>`"""
|
|
305
|
+
return _validate_dict_option(
|
|
306
|
+
scope, INDEX_HINTS_SCOPES, "HINTS scope"
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
cdef inline str validate_insert_priority(object priority):
|
|
310
|
+
"""Validate MySQL insert priority `<'str/None'>`"""
|
|
311
|
+
return _validate_dict_option(
|
|
312
|
+
priority, INSERT_PRIORITIES, "INSERT priority"
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
# . option [set]
|
|
316
|
+
cdef inline str _validate_set_option(object option, set available_options, str option_name):
|
|
317
|
+
"""Validate MySQL option [set based available options] `<'str/None'>`"""
|
|
318
|
+
if option is None:
|
|
319
|
+
return None
|
|
320
|
+
if not is_str(option):
|
|
321
|
+
raise TypeError(
|
|
322
|
+
"%s must be <'str/None'> type, instead got %s %r."
|
|
323
|
+
% (option_name, type(option), option)
|
|
324
|
+
)
|
|
325
|
+
if str_len(option) == 0:
|
|
326
|
+
return None
|
|
327
|
+
cdef str opt = option
|
|
328
|
+
opt = opt.strip()
|
|
329
|
+
opt = opt.upper()
|
|
330
|
+
if opt in ("DEFAULT", "NONE"):
|
|
331
|
+
return None
|
|
332
|
+
|
|
333
|
+
if not set_contains(available_options, opt):
|
|
334
|
+
raise ValueError(
|
|
335
|
+
"%s '%s' is invalid, must be one of: %s."
|
|
336
|
+
% (option_name, option, sorted(available_options))
|
|
337
|
+
)
|
|
338
|
+
return opt
|
|
339
|
+
|
|
340
|
+
cdef inline str validate_row_format(object row_format):
|
|
341
|
+
"""Validate MySQL row format `<'str/None'>`"""
|
|
342
|
+
return _validate_set_option(
|
|
343
|
+
row_format, ROW_FORMATS, "ROW FORMAT"
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
cdef inline str validate_index_type(object index_type):
|
|
347
|
+
"""Validate MySQL index type `<'str/None'>`"""
|
|
348
|
+
return _validate_set_option(
|
|
349
|
+
index_type, INDEX_TYPES, "INDEX TYPE"
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
cdef inline str validate_foreign_key_action(object action):
|
|
353
|
+
"""Validate MySQL foreign key action `<'str/None'>`"""
|
|
354
|
+
return _validate_set_option(
|
|
355
|
+
action, FOREIGN_KEY_ACTIONS, "FOREIGN KEY ACTION"
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
cdef inline str validate_check_table_option(object check_option):
|
|
359
|
+
"""Validate MySQL check table option `<'str/None'>`"""
|
|
360
|
+
return _validate_set_option(
|
|
361
|
+
check_option, CHECK_TABLE_OPTIONS, "TABLE CHECK OPTION"
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
cdef inline str validate_repair_table_option(object repair_option):
|
|
365
|
+
"""Validate MySQL repair table option `<'str/None'>`"""
|
|
366
|
+
return _validate_set_option(
|
|
367
|
+
repair_option, REPAIR_TABLE_OPTIONS, "TABLE REPAIR OPTION"
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
cdef inline str validate_locking_reads_option(object read_option):
|
|
371
|
+
"""Validate MySQL locking reads option `<'str/None'>`"""
|
|
372
|
+
return _validate_set_option(
|
|
373
|
+
read_option, LOCKING_READS_OPTIONS, "LOCK option"
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
# Reader -----------------------------------------------------------------------------------
|
|
377
|
+
cdef inline object read_bool_config(int value):
|
|
378
|
+
"""Read MySQL boolean value `<'int/None'>`
|
|
379
|
+
|
|
380
|
+
- Returns `None` if value == -1.
|
|
381
|
+
- Returns `False` if value == 0.
|
|
382
|
+
- Returns `True` if value == 1.
|
|
383
|
+
"""
|
|
384
|
+
if value < 0:
|
|
385
|
+
return None
|
|
386
|
+
return True if value == 1 else False
|
|
387
|
+
|
|
388
|
+
# Cleaner ----------------------------------------------------------------------------------
|
|
389
|
+
cdef inline str cleanup_expression(str expr):
|
|
390
|
+
"""Clean MySQL expression `<'str/None'>`
|
|
391
|
+
|
|
392
|
+
- If the expression starts with "(" and ends with ")",
|
|
393
|
+
the parentheses will first be removed.
|
|
394
|
+
- Remove all leading and trailing whitespaces.
|
|
395
|
+
"""
|
|
396
|
+
if expr is None:
|
|
397
|
+
return None
|
|
398
|
+
expr = expr.strip()
|
|
399
|
+
cdef Py_ssize_t size = str_len(expr)
|
|
400
|
+
if size == 0:
|
|
401
|
+
return None
|
|
402
|
+
if (
|
|
403
|
+
str_tailmatch(expr, "(", 0, size, -1) # expr.startwith("(")
|
|
404
|
+
and str_tailmatch(expr, ")", 0, size, 1) # expr.endswith(")")
|
|
405
|
+
):
|
|
406
|
+
expr = str_substr(expr, 1, size - 1)
|
|
407
|
+
expr = expr.strip()
|
|
408
|
+
return expr
|
|
409
|
+
|
|
410
|
+
# Partitioning -----------------------------------------------------------------------------
|
|
411
|
+
ctypedef enum PARTITIONING_METHOD:
|
|
412
|
+
NONSET
|
|
413
|
+
# Method
|
|
414
|
+
HASH
|
|
415
|
+
LINEAR_HASH
|
|
416
|
+
KEY
|
|
417
|
+
LINEAR_KEY
|
|
418
|
+
RANGE
|
|
419
|
+
RANGE_COLUMNS
|
|
420
|
+
LIST
|
|
421
|
+
LIST_COLUMNS
|
|
422
|
+
|
|
423
|
+
cdef inline str partitioning_flag_to_method(int flag):
|
|
424
|
+
"""Convert partitioning integer flag to its corresponding string method `<'str'>`."""
|
|
425
|
+
# Range
|
|
426
|
+
if flag == PARTITIONING_METHOD.RANGE:
|
|
427
|
+
return "RANGE"
|
|
428
|
+
if flag == PARTITIONING_METHOD.RANGE_COLUMNS:
|
|
429
|
+
return "RANGE COLUMNS"
|
|
430
|
+
# Hash
|
|
431
|
+
if flag == PARTITIONING_METHOD.HASH:
|
|
432
|
+
return "HASH"
|
|
433
|
+
if flag == PARTITIONING_METHOD.LINEAR_HASH:
|
|
434
|
+
return "LINEAR HASH"
|
|
435
|
+
# List
|
|
436
|
+
if flag == PARTITIONING_METHOD.LIST:
|
|
437
|
+
return "LIST"
|
|
438
|
+
if flag == PARTITIONING_METHOD.LIST_COLUMNS:
|
|
439
|
+
return "LIST COLUMNS"
|
|
440
|
+
# Key
|
|
441
|
+
if flag == PARTITIONING_METHOD.KEY:
|
|
442
|
+
return "KEY"
|
|
443
|
+
if flag == PARTITIONING_METHOD.LINEAR_KEY:
|
|
444
|
+
return "LINEAR KEY"
|
|
445
|
+
# Invalid
|
|
446
|
+
raise ValueError("partitioning flag %d is invalid, must be between 1 and 8." % flag)
|
|
447
|
+
|
|
448
|
+
cdef inline int partitioning_method_to_flag(str method) except -1:
|
|
449
|
+
"""Convert partitioning method to its corresponding integer flag `<'int'>`."""
|
|
450
|
+
if method is not None:
|
|
451
|
+
if method == "RANGE":
|
|
452
|
+
return PARTITIONING_METHOD.RANGE
|
|
453
|
+
if method == "RANGE COLUMNS":
|
|
454
|
+
return PARTITIONING_METHOD.RANGE_COLUMNS
|
|
455
|
+
# Hash
|
|
456
|
+
if method == "HASH":
|
|
457
|
+
return PARTITIONING_METHOD.HASH
|
|
458
|
+
if method == "LINEAR HASH":
|
|
459
|
+
return PARTITIONING_METHOD.LINEAR_HASH
|
|
460
|
+
# List
|
|
461
|
+
if method == "LIST":
|
|
462
|
+
return PARTITIONING_METHOD.LIST
|
|
463
|
+
if method == "LIST COLUMNS":
|
|
464
|
+
return PARTITIONING_METHOD.LIST_COLUMNS
|
|
465
|
+
# Key
|
|
466
|
+
if method == "KEY":
|
|
467
|
+
return PARTITIONING_METHOD.KEY
|
|
468
|
+
if method == "LINEAR KEY":
|
|
469
|
+
return PARTITIONING_METHOD.LINEAR_KEY
|
|
470
|
+
raise ValueError(
|
|
471
|
+
"partitioning method '%s' is invalid, must be one of:\n"
|
|
472
|
+
"('HASH', 'LINEAR HASH', 'KEY', 'LINEAR KEY', 'RANGE', "
|
|
473
|
+
"'RANGE COLUMNS', 'LIST', 'LIST COLUMNS')." % method
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
cdef inline bint is_partition_by_hash(int flag) except -1:
|
|
477
|
+
"""Check if the partitioning flag represents PARTITIION BY (LINEAR) HASH `<'bool'>`."""
|
|
478
|
+
return flag in (PARTITIONING_METHOD.HASH, PARTITIONING_METHOD.LINEAR_HASH)
|
|
479
|
+
|
|
480
|
+
cdef inline bint is_partition_by_key(int flag) except -1:
|
|
481
|
+
"""Check if the partitioning flag represents PARTITIION BY (LINEAR) KEY `<'bool'>`."""
|
|
482
|
+
return flag in (PARTITIONING_METHOD.KEY, PARTITIONING_METHOD.LINEAR_KEY)
|
|
483
|
+
|
|
484
|
+
cdef inline bint is_partition_by_range(int flag) except -1:
|
|
485
|
+
"""Check if the partitioning flag represents PARTITIION BY RANGE (COLUMNS) `<'bool'>`."""
|
|
486
|
+
return flag in (PARTITIONING_METHOD.RANGE, PARTITIONING_METHOD.RANGE_COLUMNS)
|
|
487
|
+
|
|
488
|
+
cdef inline bint is_partition_by_list(int flag) except -1:
|
|
489
|
+
"""Check if the partitioning flag represents PARTITIION BY LIST (COLUMNS) `<'bool'>`."""
|
|
490
|
+
return flag in (PARTITIONING_METHOD.LIST, PARTITIONING_METHOD.LIST_COLUMNS)
|
|
491
|
+
|
|
492
|
+
cdef inline bint is_partition_by_hashkey(int flag) except -1:
|
|
493
|
+
"""Check if the partitioning flag represents PARTITIION BY (LINEAR) HASH/KEY `<'bool'>`."""
|
|
494
|
+
return is_partition_by_hash(flag) or is_partition_by_key(flag)
|
|
495
|
+
|
|
496
|
+
cdef inline bint is_partition_by_rangelist(int flag) except -1:
|
|
497
|
+
"""Check if the partitioning flag represents PARTITION BY RANGE/LIST (COLUMNS) `<'bool'>`."""
|
|
498
|
+
return is_partition_by_range(flag) or is_partition_by_list(flag)
|
|
499
|
+
|
|
500
|
+
cdef inline bint is_partitioning_flag_valid(int flag) except -1:
|
|
501
|
+
"""Check if the partitioning flag is valid (1-8) `<'bool'>`."""
|
|
502
|
+
return flag in (
|
|
503
|
+
PARTITIONING_METHOD.RANGE,
|
|
504
|
+
PARTITIONING_METHOD.RANGE_COLUMNS,
|
|
505
|
+
PARTITIONING_METHOD.HASH,
|
|
506
|
+
PARTITIONING_METHOD.LINEAR_HASH,
|
|
507
|
+
PARTITIONING_METHOD.KEY,
|
|
508
|
+
PARTITIONING_METHOD.LINEAR_KEY,
|
|
509
|
+
PARTITIONING_METHOD.LIST,
|
|
510
|
+
PARTITIONING_METHOD.LIST_COLUMNS,
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
# DML Clause -------------------------------------------------------------------------------
|
|
514
|
+
ctypedef enum DML_CLAUSE:
|
|
515
|
+
NONE
|
|
516
|
+
# WITH
|
|
517
|
+
WITH
|
|
518
|
+
# Delete
|
|
519
|
+
DELETE
|
|
520
|
+
# Update
|
|
521
|
+
UPDATE
|
|
522
|
+
# Insert
|
|
523
|
+
INSERT
|
|
524
|
+
INSERT_COLUMNS
|
|
525
|
+
INSERT_VALUES
|
|
526
|
+
SET
|
|
527
|
+
ON_DUPLICATE
|
|
528
|
+
# Select
|
|
529
|
+
SELECT
|
|
530
|
+
FROM
|
|
531
|
+
JOIN
|
|
532
|
+
WHERE
|
|
533
|
+
GROUP_BY
|
|
534
|
+
HAVING
|
|
535
|
+
WINDOW
|
|
536
|
+
SET_OPERATION
|
|
537
|
+
ORDER_BY
|
|
538
|
+
LIMIT
|
|
539
|
+
LOCKING_READS
|
|
540
|
+
INTO
|
|
541
|
+
|
|
542
|
+
ctypedef enum INSERT_MODE:
|
|
543
|
+
INCOMPLETE
|
|
544
|
+
# Mode
|
|
545
|
+
VALUES_MODE
|
|
546
|
+
SET_MODE
|
|
547
|
+
SELECT_MODE
|
|
548
|
+
|
|
549
|
+
# TimeTable --------------------------------------------------------------------------------
|
|
550
|
+
ctypedef enum TIMETABLE_UNIT:
|
|
551
|
+
UNKNOWN
|
|
552
|
+
# Unit
|
|
553
|
+
YEAR
|
|
554
|
+
QUARTER
|
|
555
|
+
MONTH
|
|
556
|
+
WEEK
|
|
557
|
+
DAY
|
|
558
|
+
HOUR
|
|
559
|
+
MINUTE
|
|
560
|
+
SECOND
|
|
561
|
+
|
|
562
|
+
cdef inline str validate_timetable_unit(object unit):
|
|
563
|
+
"""Validate MySQL storage engine `<'str/None'>`."""
|
|
564
|
+
return _validate_dict_option(
|
|
565
|
+
unit, TIMETABLE_UNITS, "time unit"
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
cdef inline str timetable_unit_flag_to_str(int flag):
|
|
569
|
+
"""Convert time table unit integer flag to its corresponding string representation `<'str'>`."""
|
|
570
|
+
if flag == TIMETABLE_UNIT.YEAR:
|
|
571
|
+
return "YEAR"
|
|
572
|
+
if flag == TIMETABLE_UNIT.QUARTER:
|
|
573
|
+
return "QUARTER"
|
|
574
|
+
if flag == TIMETABLE_UNIT.MONTH:
|
|
575
|
+
return "MONTH"
|
|
576
|
+
if flag == TIMETABLE_UNIT.WEEK:
|
|
577
|
+
return "WEEK"
|
|
578
|
+
if flag == TIMETABLE_UNIT.DAY:
|
|
579
|
+
return "DAY"
|
|
580
|
+
if flag == TIMETABLE_UNIT.HOUR:
|
|
581
|
+
return "HOUR"
|
|
582
|
+
if flag == TIMETABLE_UNIT.MINUTE:
|
|
583
|
+
return "MINUTE"
|
|
584
|
+
if flag == TIMETABLE_UNIT.SECOND:
|
|
585
|
+
return "SECOND"
|
|
586
|
+
raise ValueError(
|
|
587
|
+
"time unit flag %d is invalid, must be between 1 and 8." % flag
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
cdef inline int timetable_unit_str_to_flag(str unit) except -1:
|
|
591
|
+
"""Convert time table unit string representation to its corresponding integer flag `<'int'>`."""
|
|
592
|
+
if unit is not None:
|
|
593
|
+
if unit == "YEAR":
|
|
594
|
+
return TIMETABLE_UNIT.YEAR
|
|
595
|
+
if unit == "QUARTER":
|
|
596
|
+
return TIMETABLE_UNIT.QUARTER
|
|
597
|
+
if unit == "MONTH":
|
|
598
|
+
return TIMETABLE_UNIT.MONTH
|
|
599
|
+
if unit == "WEEK":
|
|
600
|
+
return TIMETABLE_UNIT.WEEK
|
|
601
|
+
if unit == "DAY":
|
|
602
|
+
return TIMETABLE_UNIT.DAY
|
|
603
|
+
if unit == "HOUR":
|
|
604
|
+
return TIMETABLE_UNIT.HOUR
|
|
605
|
+
if unit == "MINUTE":
|
|
606
|
+
return TIMETABLE_UNIT.MINUTE
|
|
607
|
+
if unit == "SECOND":
|
|
608
|
+
return TIMETABLE_UNIT.SECOND
|
|
609
|
+
raise ValueError(
|
|
610
|
+
"time unit '%s' is invalid, must be one of:\n"
|
|
611
|
+
"('YEAR', 'QUARTER', 'MONTH', 'WEEK', 'DAY', "
|
|
612
|
+
"'HOUR', 'MINUTE', 'SECOND')" % unit
|
|
613
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mysqlengine
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: A Cython-Accelerated, Pythonic MySQL ORM & Query Builder
|
|
5
5
|
Home-page: https://github.com/AresJef/MysqlEngine
|
|
6
6
|
Author: Jiefu Chen
|
|
@@ -14,11 +14,10 @@ Classifier: Operating System :: Microsoft :: Windows
|
|
|
14
14
|
Requires-Python: >=3.10
|
|
15
15
|
Description-Content-Type: text/markdown
|
|
16
16
|
License-File: LICENSE
|
|
17
|
-
Requires-Dist: cytimes>=2.
|
|
17
|
+
Requires-Dist: cytimes>=2.1.1
|
|
18
18
|
Requires-Dist: numpy>=1.25.2
|
|
19
19
|
Requires-Dist: pandas>=2.1.0
|
|
20
|
-
Requires-Dist:
|
|
21
|
-
Requires-Dist: sqlcycli>=1.5.0
|
|
20
|
+
Requires-Dist: sqlcycli>=1.5.2
|
|
22
21
|
Requires-Dist: typing-extensions>=4.9.0
|
|
23
22
|
Dynamic: license-file
|
|
24
23
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
mysqlengine/utils.pxd,sha256=PkYVesEQBaock61nBZzCuSL1X2eYltC8u0CKK41nZLU,20587
|
|
2
|
+
mysqlengine/constraint.c,sha256=xsXnCPBbN4kIneEJ2we5SpPQIFk8R9F0vuyvAxbZ5Bk,4590285
|
|
3
|
+
mysqlengine/column.c,sha256=_Nb40_FjumC3U2jd1Kxt8y7DjVeeywV64DK4ssAE8iU,7770651
|
|
4
|
+
mysqlengine/partition.cpython-313-darwin.so,sha256=3A76xQH3oNhO42bb1UheI2q250r_wMvvWTqKivBG-WM,2202784
|
|
5
|
+
mysqlengine/constraint.py,sha256=D_Yuq3CufY75HKgbZqJoUtb9LBklrH4mCnNHWl7fNyY,118196
|
|
6
|
+
mysqlengine/dml.cpython-313-darwin.so,sha256=mC7I0CTU3kO8XIVj6wcka_ZFpyLrfBhRPfw8adiX_HE,3554888
|
|
7
|
+
mysqlengine/element.c,sha256=TuVBw2Inb9SR6JYExKybtxTozj3m77LqPSx_AHvmV6k,3653047
|
|
8
|
+
mysqlengine/utils.cpython-313-darwin.so,sha256=bsX9PBy0aIegCShDtmvoT-m4kPVqhNwHz8xajROI9xg,271000
|
|
9
|
+
mysqlengine/column.pxd,sha256=t-Ln3rbMtQC33cKV8pbD-ZyWPoxq8-kqNmiIOMMnE_I,4571
|
|
10
|
+
mysqlengine/table.pxd,sha256=e2La6k7kBvNa8W6qM1FZpEEt8Lzv97hyVcWOW1Px6ps,6728
|
|
11
|
+
mysqlengine/partition.py,sha256=jDQhxS27j7Sqy7MbtjkqsHwKhqzumnyVIkS4UAvabt4,115437
|
|
12
|
+
mysqlengine/constraint.pyi,sha256=5h88olpPSsB_FKc3O-b25E2ontovgGd9T08xi6RmWxQ,9413
|
|
13
|
+
mysqlengine/table.c,sha256=evybZPuLTBbOjouDKi9qWn9Ckdc7vnvC3lbnYJxTdNI,6035741
|
|
14
|
+
mysqlengine/index.py,sha256=8ewTc3LnVB90lWYpOEpHNE8-lljT0Yab5emwDX78Brc,51264
|
|
15
|
+
mysqlengine/partition.c,sha256=5zEmyi_6x3cztaCe1YKIBM-B1EH3fPF-Qd2RDdYJyEM,4811405
|
|
16
|
+
mysqlengine/database.c,sha256=yrUfZU1O6BbF3Ya_MivmB9kirmM5OVxL3cCVklp7zWY,2687933
|
|
17
|
+
mysqlengine/__init__.pxd,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
mysqlengine/database.py,sha256=O4TICaLIXmyXL7s1egcUbT3z1UvtGsZFg5E2xatdHFM,60079
|
|
19
|
+
mysqlengine/constraint.pxd,sha256=bBiUhU2TVekRsRSIczoHlrlpZwqIvHxOwx86mQdoU34,3710
|
|
20
|
+
mysqlengine/table.pyi,sha256=z80-zjEWsEBMV_sg5_O2DXt0vzYbkwWTX_2WiRuk93k,14352
|
|
21
|
+
mysqlengine/__init__.py,sha256=WGE5Rsl4RPXcV2H2VgFijWe-vEJ_XHb2pZdYudm-vww,2689
|
|
22
|
+
mysqlengine/column.pyi,sha256=hOJy_DagY20zYKaqiroLIE2fCwOkMarGH_635j_oMFo,21514
|
|
23
|
+
mysqlengine/table.cpython-313-darwin.so,sha256=bko6wyG_WTdEUXjyj99l7OeeOiMggVQTE1IzEsGXPCc,2793336
|
|
24
|
+
mysqlengine/database.cpython-313-darwin.so,sha256=tnPLflpNVkIWjOzPUpGLDGr38c3VxlIPzL8Swfor2Ac,1100608
|
|
25
|
+
mysqlengine/column.cpython-313-darwin.so,sha256=Vr6DnT76-nmWKj--eaGiK9XUPhLClRzYfXRUcrzdqlE,3464624
|
|
26
|
+
mysqlengine/constraint.cpython-313-darwin.so,sha256=HY0z4KaH9F2RvF_z5ucR24agLC9FL4XYT_LjlxwucJs,2083072
|
|
27
|
+
mysqlengine/element.py,sha256=NCa1VPMFjWrq_qBCRzzBQqrT6g1fdecX22z0ghlsJ50,85438
|
|
28
|
+
mysqlengine/element.cpython-313-darwin.so,sha256=hEPwPVqRQD6rL-W9V2WQpQq9k73YrBN2PkAuqAerRME,1416512
|
|
29
|
+
mysqlengine/utils.pyi,sha256=eV3nbosNLjBdu3cdD2g0uCPZro5J202JTWB22gW_FUg,9201
|
|
30
|
+
mysqlengine/database.pxd,sha256=1c12P7kerFsgWyxQ_RDbL83aEw_vXqaLrxnGvm5jpJw,2421
|
|
31
|
+
mysqlengine/partition.pxd,sha256=uN4MiBNHtb-UCfEslVSGxukPhU5qO_aQlfQjPq8s7mQ,5124
|
|
32
|
+
mysqlengine/index.cpython-313-darwin.so,sha256=gf8IZgq_oMQm5i0bQIefONRt4DSjtph11Lj1wW41RXQ,1259992
|
|
33
|
+
mysqlengine/index.pyi,sha256=NlvNNcMpvboIGeKH5Iezy7a4Dz5yIHDTB8KAI_PhCG0,5469
|
|
34
|
+
mysqlengine/index.c,sha256=nrzm5PsRau4tZywmd4NAohqQIg1jCl4gdJDLzbiHzHg,2891498
|
|
35
|
+
mysqlengine/utils.c,sha256=s8X4YCyGM8rJXSmWixu_snFP0JyM_k0tgfp1MS8c9ds,812271
|
|
36
|
+
mysqlengine/utils.py,sha256=QSpiXnLl219K13cqic4LMAhwTjTDwuMuEq72muBUaSM,5017
|
|
37
|
+
mysqlengine/dml.pyi,sha256=7YaGQmehsxNiRj7eCvBt_IpveIKBf5RLJI_MSELmmDA,23535
|
|
38
|
+
mysqlengine/table.py,sha256=09rEGYj9qmrbeSTIoe51kwfMx6zrvwtUJmCHHIwX66k,177394
|
|
39
|
+
mysqlengine/errors.py,sha256=I0JYunZDn9WBIAatay33z04huOEGBBkSVMEApTd7W_o,8197
|
|
40
|
+
mysqlengine/element.pxd,sha256=AaEUI2IUwr1t7YG1BclR42PGBrugx2nRZaAai6r4dzM,7394
|
|
41
|
+
mysqlengine/dml.pxd,sha256=EPkniXh7JSsyWJ5H5zkQ0h63KP_HbRKKm4naAfGiOCo,15187
|
|
42
|
+
mysqlengine/dml.c,sha256=UPDtoDUuiA3Y7tdBjRsAeMloJZE6srzKKj-Dq75Du3I,7651599
|
|
43
|
+
mysqlengine/dml.py,sha256=1nWfgaY4qYaA_MUnErwQmyRyclS4OZWAZN9T3hTp5T8,356123
|
|
44
|
+
mysqlengine/index.pxd,sha256=Pd69Bp_GUS5ZcPmYKrAhScYeLhEJYIVVKDCgyuo-lXk,2327
|
|
45
|
+
mysqlengine/column.py,sha256=EGzL1-biMNuK3wefcFMKtzPeiotyaoNg76beyaX0Ko0,196000
|
|
46
|
+
mysqlengine/database.pyi,sha256=52NBXA0AysYmq1ixblkTR2911ehgryoLZTyoDUopU2A,5097
|
|
47
|
+
mysqlengine/partition.pyi,sha256=FQ8SmroQ4BFPnKhNk8wLMyKDMHl7YyMIyvVpsztw-e0,8786
|
|
48
|
+
mysqlengine-1.0.3.dist-info/RECORD,,
|
|
49
|
+
mysqlengine-1.0.3.dist-info/WHEEL,sha256=memlX0NSEQnmSMa3rcNWPnk4cttudwgAZx3qq8qO4ME,115
|
|
50
|
+
mysqlengine-1.0.3.dist-info/top_level.txt,sha256=WSdkY5_BsytOI3l-Gt-lRq2R-SYHMPYHV8zJICB79_Y,12
|
|
51
|
+
mysqlengine-1.0.3.dist-info/METADATA,sha256=GO4oq0kldSjYlucwnFZI4PEzlb-Yn5sjZG_4N3aPNm4,7952
|
|
52
|
+
mysqlengine-1.0.3.dist-info/licenses/LICENSE,sha256=JhlhA0azh7jMOTVMYyfKoEj5dFIKd4N6aJ-g_cy7Q-Y,1082
|