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/utils.c CHANGED
@@ -1779,10 +1779,11 @@ struct __pyx_obj_8sqlcycli_7charset_Charset {
1779
1779
  PyObject *_encoding;
1780
1780
  char *_encoding_c;
1781
1781
  int _is_default;
1782
+ Py_ssize_t _hashcode;
1782
1783
  };
1783
1784
 
1784
1785
 
1785
- /* "sqlcycli/charset.pxd":15
1786
+ /* "sqlcycli/charset.pxd":16
1786
1787
  * cpdef bint is_binary(self)
1787
1788
  *
1788
1789
  * cdef class Charsets: # <<<<<<<<<<<<<<
@@ -1885,7 +1886,7 @@ struct __pyx_vtabstruct_8sqlcycli_7charset_Charset {
1885
1886
  static struct __pyx_vtabstruct_8sqlcycli_7charset_Charset *__pyx_vtabptr_8sqlcycli_7charset_Charset;
1886
1887
 
1887
1888
 
1888
- /* "sqlcycli/charset.pxd":15
1889
+ /* "sqlcycli/charset.pxd":16
1889
1890
  * cpdef bint is_binary(self)
1890
1891
  *
1891
1892
  * cdef class Charsets: # <<<<<<<<<<<<<<
@@ -1895,10 +1896,10 @@ static struct __pyx_vtabstruct_8sqlcycli_7charset_Charset *__pyx_vtabptr_8sqlcyc
1895
1896
 
1896
1897
  struct __pyx_vtabstruct_8sqlcycli_7charset_Charsets {
1897
1898
  int (*add)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *, int __pyx_skip_dispatch);
1898
- int (*_add_by_id)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *);
1899
- int (*_add_by_name)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *);
1900
- int (*_add_by_collation)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *);
1901
- int (*_add_by_name_n_collation)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *);
1899
+ int (*_index_by_id)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *);
1900
+ int (*_index_by_name)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *);
1901
+ int (*_index_by_collation)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *);
1902
+ int (*_index_by_name_n_collation)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, struct __pyx_obj_8sqlcycli_7charset_Charset *);
1902
1903
  PyObject *(*_gen_charset_n_collate_key)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, PyObject *, PyObject *);
1903
1904
  struct __pyx_obj_8sqlcycli_7charset_Charset *(*by_id)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, PyObject *, int __pyx_skip_dispatch);
1904
1905
  struct __pyx_obj_8sqlcycli_7charset_Charset *(*by_name)(struct __pyx_obj_8sqlcycli_7charset_Charsets *, PyObject *, int __pyx_skip_dispatch);
@@ -14515,8 +14516,8 @@ static int __Pyx_modinit_type_import_code(void) {
14515
14516
  __Pyx_GOTREF(__pyx_t_1);
14516
14517
  __pyx_ptype_8sqlcycli_7charset_Charset = __Pyx_ImportType_3_0_12(__pyx_t_1, "sqlcycli.charset", "Charset", sizeof(struct __pyx_obj_8sqlcycli_7charset_Charset), __PYX_GET_STRUCT_ALIGNMENT_3_0_12(struct __pyx_obj_8sqlcycli_7charset_Charset),__Pyx_ImportType_CheckSize_Warn_3_0_12); if (!__pyx_ptype_8sqlcycli_7charset_Charset) __PYX_ERR(8, 4, __pyx_L1_error)
14517
14518
  __pyx_vtabptr_8sqlcycli_7charset_Charset = (struct __pyx_vtabstruct_8sqlcycli_7charset_Charset*)__Pyx_GetVtable(__pyx_ptype_8sqlcycli_7charset_Charset); if (unlikely(!__pyx_vtabptr_8sqlcycli_7charset_Charset)) __PYX_ERR(8, 4, __pyx_L1_error)
14518
- __pyx_ptype_8sqlcycli_7charset_Charsets = __Pyx_ImportType_3_0_12(__pyx_t_1, "sqlcycli.charset", "Charsets", sizeof(struct __pyx_obj_8sqlcycli_7charset_Charsets), __PYX_GET_STRUCT_ALIGNMENT_3_0_12(struct __pyx_obj_8sqlcycli_7charset_Charsets),__Pyx_ImportType_CheckSize_Warn_3_0_12); if (!__pyx_ptype_8sqlcycli_7charset_Charsets) __PYX_ERR(8, 15, __pyx_L1_error)
14519
- __pyx_vtabptr_8sqlcycli_7charset_Charsets = (struct __pyx_vtabstruct_8sqlcycli_7charset_Charsets*)__Pyx_GetVtable(__pyx_ptype_8sqlcycli_7charset_Charsets); if (unlikely(!__pyx_vtabptr_8sqlcycli_7charset_Charsets)) __PYX_ERR(8, 15, __pyx_L1_error)
14519
+ __pyx_ptype_8sqlcycli_7charset_Charsets = __Pyx_ImportType_3_0_12(__pyx_t_1, "sqlcycli.charset", "Charsets", sizeof(struct __pyx_obj_8sqlcycli_7charset_Charsets), __PYX_GET_STRUCT_ALIGNMENT_3_0_12(struct __pyx_obj_8sqlcycli_7charset_Charsets),__Pyx_ImportType_CheckSize_Warn_3_0_12); if (!__pyx_ptype_8sqlcycli_7charset_Charsets) __PYX_ERR(8, 16, __pyx_L1_error)
14520
+ __pyx_vtabptr_8sqlcycli_7charset_Charsets = (struct __pyx_vtabstruct_8sqlcycli_7charset_Charsets*)__Pyx_GetVtable(__pyx_ptype_8sqlcycli_7charset_Charsets); if (unlikely(!__pyx_vtabptr_8sqlcycli_7charset_Charsets)) __PYX_ERR(8, 16, __pyx_L1_error)
14520
14521
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
14521
14522
  __pyx_t_1 = PyImport_ImportModule("sqlcycli.sqlfunc"); if (unlikely(!__pyx_t_1)) __PYX_ERR(9, 9, __pyx_L1_error)
14522
14523
  __Pyx_GOTREF(__pyx_t_1);
Binary file
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.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.0.7
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: pyarrow>=13.0.0
21
- Requires-Dist: sqlcycli>=1.4.6
20
+ Requires-Dist: sqlcycli>=1.5.2
22
21
  Requires-Dist: typing-extensions>=4.9.0
23
22
  Dynamic: license-file
24
23