ormlambda 3.12.2__py3-none-any.whl → 3.34.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. ormlambda/__init__.py +2 -0
  2. ormlambda/caster/__init__.py +1 -1
  3. ormlambda/caster/caster.py +29 -12
  4. ormlambda/common/abstract_classes/clause_info_converter.py +4 -12
  5. ormlambda/common/abstract_classes/decomposition_query.py +17 -2
  6. ormlambda/common/abstract_classes/non_query_base.py +9 -7
  7. ormlambda/common/abstract_classes/query_base.py +3 -1
  8. ormlambda/common/errors/__init__.py +29 -0
  9. ormlambda/common/interfaces/IQueryCommand.py +6 -2
  10. ormlambda/databases/__init__.py +0 -1
  11. ormlambda/databases/my_sql/__init__.py +0 -1
  12. ormlambda/databases/my_sql/caster/caster.py +23 -19
  13. ormlambda/databases/my_sql/caster/types/__init__.py +3 -0
  14. ormlambda/databases/my_sql/caster/types/boolean.py +35 -0
  15. ormlambda/databases/my_sql/caster/types/bytes.py +7 -7
  16. ormlambda/databases/my_sql/caster/types/date.py +34 -0
  17. ormlambda/databases/my_sql/caster/types/datetime.py +7 -7
  18. ormlambda/databases/my_sql/caster/types/decimal.py +32 -0
  19. ormlambda/databases/my_sql/caster/types/float.py +7 -7
  20. ormlambda/databases/my_sql/caster/types/int.py +7 -7
  21. ormlambda/databases/my_sql/caster/types/iterable.py +7 -7
  22. ormlambda/databases/my_sql/caster/types/none.py +8 -7
  23. ormlambda/databases/my_sql/caster/types/point.py +4 -4
  24. ormlambda/databases/my_sql/caster/types/string.py +7 -7
  25. ormlambda/databases/my_sql/clauses/ST_AsText.py +8 -7
  26. ormlambda/databases/my_sql/clauses/ST_Contains.py +10 -5
  27. ormlambda/databases/my_sql/clauses/__init__.py +4 -10
  28. ormlambda/databases/my_sql/clauses/count.py +5 -15
  29. ormlambda/databases/my_sql/clauses/delete.py +3 -50
  30. ormlambda/databases/my_sql/clauses/group_by.py +3 -16
  31. ormlambda/databases/my_sql/clauses/having.py +2 -6
  32. ormlambda/databases/my_sql/clauses/insert.py +4 -92
  33. ormlambda/databases/my_sql/clauses/joins.py +5 -140
  34. ormlambda/databases/my_sql/clauses/limit.py +4 -15
  35. ormlambda/databases/my_sql/clauses/offset.py +4 -15
  36. ormlambda/databases/my_sql/clauses/order.py +4 -61
  37. ormlambda/databases/my_sql/clauses/update.py +4 -67
  38. ormlambda/databases/my_sql/clauses/upsert.py +3 -66
  39. ormlambda/databases/my_sql/clauses/where.py +4 -42
  40. ormlambda/databases/my_sql/repository.py +217 -0
  41. ormlambda/dialects/__init__.py +39 -0
  42. ormlambda/dialects/default/__init__.py +1 -0
  43. ormlambda/dialects/default/base.py +39 -0
  44. ormlambda/dialects/interface/__init__.py +1 -0
  45. ormlambda/dialects/interface/dialect.py +78 -0
  46. ormlambda/dialects/mysql/__init__.py +8 -0
  47. ormlambda/dialects/mysql/base.py +387 -0
  48. ormlambda/dialects/mysql/mysqlconnector.py +46 -0
  49. ormlambda/dialects/mysql/types.py +732 -0
  50. ormlambda/dialects/sqlite/__init__.py +5 -0
  51. ormlambda/dialects/sqlite/base.py +47 -0
  52. ormlambda/dialects/sqlite/pysqlite.py +32 -0
  53. ormlambda/engine/__init__.py +1 -0
  54. ormlambda/engine/base.py +58 -0
  55. ormlambda/engine/create.py +9 -23
  56. ormlambda/engine/url.py +31 -19
  57. ormlambda/env.py +30 -0
  58. ormlambda/errors.py +17 -0
  59. ormlambda/model/base_model.py +7 -9
  60. ormlambda/repository/base_repository.py +36 -5
  61. ormlambda/repository/interfaces/IRepositoryBase.py +121 -7
  62. ormlambda/repository/response.py +134 -0
  63. ormlambda/sql/clause_info/aggregate_function_base.py +19 -9
  64. ormlambda/sql/clause_info/clause_info.py +34 -17
  65. ormlambda/sql/clauses/__init__.py +14 -0
  66. ormlambda/{databases/my_sql → sql}/clauses/alias.py +23 -6
  67. ormlambda/sql/clauses/count.py +57 -0
  68. ormlambda/sql/clauses/delete.py +71 -0
  69. ormlambda/sql/clauses/group_by.py +30 -0
  70. ormlambda/sql/clauses/having.py +21 -0
  71. ormlambda/sql/clauses/insert.py +104 -0
  72. ormlambda/sql/clauses/interfaces/__init__.py +5 -0
  73. ormlambda/{components → sql/clauses}/join/join_context.py +15 -7
  74. ormlambda/sql/clauses/joins.py +159 -0
  75. ormlambda/sql/clauses/limit.py +15 -0
  76. ormlambda/sql/clauses/offset.py +15 -0
  77. ormlambda/sql/clauses/order.py +55 -0
  78. ormlambda/{databases/my_sql → sql}/clauses/select.py +12 -13
  79. ormlambda/sql/clauses/update.py +84 -0
  80. ormlambda/sql/clauses/upsert.py +77 -0
  81. ormlambda/sql/clauses/where.py +65 -0
  82. ormlambda/sql/column/__init__.py +1 -0
  83. ormlambda/sql/{column.py → column/column.py} +82 -22
  84. ormlambda/sql/comparer.py +51 -37
  85. ormlambda/sql/compiler.py +427 -0
  86. ormlambda/sql/ddl.py +68 -0
  87. ormlambda/sql/elements.py +36 -0
  88. ormlambda/sql/foreign_key.py +43 -39
  89. ormlambda/{databases/my_sql → sql}/functions/concat.py +13 -5
  90. ormlambda/{databases/my_sql → sql}/functions/max.py +9 -4
  91. ormlambda/{databases/my_sql → sql}/functions/min.py +9 -13
  92. ormlambda/{databases/my_sql → sql}/functions/sum.py +8 -10
  93. ormlambda/sql/sqltypes.py +647 -0
  94. ormlambda/sql/table/__init__.py +1 -1
  95. ormlambda/sql/table/table.py +179 -0
  96. ormlambda/sql/table/table_constructor.py +1 -208
  97. ormlambda/sql/type_api.py +35 -0
  98. ormlambda/sql/types.py +3 -1
  99. ormlambda/sql/visitors.py +74 -0
  100. ormlambda/statements/__init__.py +1 -0
  101. ormlambda/statements/base_statement.py +28 -38
  102. ormlambda/statements/interfaces/IStatements.py +5 -4
  103. ormlambda/{databases/my_sql → statements}/query_builder.py +35 -30
  104. ormlambda/{databases/my_sql → statements}/statements.py +50 -60
  105. ormlambda/statements/types.py +2 -2
  106. ormlambda/types/__init__.py +24 -0
  107. ormlambda/types/metadata.py +42 -0
  108. ormlambda/util/__init__.py +88 -0
  109. ormlambda/util/load_module.py +21 -0
  110. ormlambda/util/plugin_loader.py +32 -0
  111. ormlambda/util/typing.py +6 -0
  112. ormlambda-3.34.1.dist-info/AUTHORS +32 -0
  113. {ormlambda-3.12.2.dist-info → ormlambda-3.34.1.dist-info}/METADATA +2 -3
  114. ormlambda-3.34.1.dist-info/RECORD +157 -0
  115. {ormlambda-3.12.2.dist-info → ormlambda-3.34.1.dist-info}/WHEEL +1 -1
  116. ormlambda/components/__init__.py +0 -4
  117. ormlambda/components/delete/__init__.py +0 -2
  118. ormlambda/components/delete/abstract_delete.py +0 -17
  119. ormlambda/components/insert/__init__.py +0 -2
  120. ormlambda/components/insert/abstract_insert.py +0 -25
  121. ormlambda/components/select/__init__.py +0 -1
  122. ormlambda/components/update/__init__.py +0 -2
  123. ormlambda/components/update/abstract_update.py +0 -29
  124. ormlambda/components/upsert/__init__.py +0 -2
  125. ormlambda/components/upsert/abstract_upsert.py +0 -25
  126. ormlambda/databases/my_sql/clauses/create_database.py +0 -35
  127. ormlambda/databases/my_sql/clauses/drop_database.py +0 -17
  128. ormlambda/databases/my_sql/repository/__init__.py +0 -1
  129. ormlambda/databases/my_sql/repository/repository.py +0 -351
  130. ormlambda/engine/template.py +0 -47
  131. ormlambda/sql/dtypes.py +0 -94
  132. ormlambda/utils/__init__.py +0 -1
  133. ormlambda-3.12.2.dist-info/RECORD +0 -125
  134. /ormlambda/databases/my_sql/{types.py → pool_types.py} +0 -0
  135. /ormlambda/{components/delete → sql/clauses/interfaces}/IDelete.py +0 -0
  136. /ormlambda/{components/insert → sql/clauses/interfaces}/IInsert.py +0 -0
  137. /ormlambda/{components/select → sql/clauses/interfaces}/ISelect.py +0 -0
  138. /ormlambda/{components/update → sql/clauses/interfaces}/IUpdate.py +0 -0
  139. /ormlambda/{components/upsert → sql/clauses/interfaces}/IUpsert.py +0 -0
  140. /ormlambda/{components → sql/clauses}/join/__init__.py +0 -0
  141. /ormlambda/{databases/my_sql → sql}/functions/__init__.py +0 -0
  142. /ormlambda/{utils → util}/module_tree/__init__.py +0 -0
  143. /ormlambda/{utils → util}/module_tree/dfs_traversal.py +0 -0
  144. /ormlambda/{utils → util}/module_tree/dynamic_module.py +0 -0
  145. {ormlambda-3.12.2.dist-info → ormlambda-3.34.1.dist-info}/LICENSE +0 -0
@@ -0,0 +1,732 @@
1
+ # dialects/mysql/types.py
2
+ # Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
3
+ # <see AUTHORS file>
4
+ #
5
+ # This module is part of SQLAlchemy and is released under
6
+ # the MIT License: https://www.opensource.org/licenses/mit-license.php
7
+ # mypy: ignore-errors
8
+
9
+
10
+ import datetime
11
+
12
+ from ormlambda.sql import sqltypes
13
+
14
+
15
+ class _NumericCommonType:
16
+ """Base for MySQL numeric types.
17
+
18
+ This is the base both for NUMERIC as well as INTEGER, hence
19
+ it's a mixin.
20
+
21
+ """
22
+
23
+ def __init__(self, unsigned=False, zerofill=False, **kw):
24
+ self.unsigned = unsigned
25
+ self.zerofill = zerofill
26
+ super().__init__(**kw)
27
+
28
+
29
+ class _NumericType(_NumericCommonType, sqltypes.Numeric): ...
30
+
31
+
32
+ class _FloatType(_NumericCommonType, sqltypes.Float):
33
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
34
+ if isinstance(self, (REAL, DOUBLE)) and ((precision is None and scale is not None) or (precision is not None and scale is None)):
35
+ raise AttributeError("You must specify both precision and scale or omit " "both altogether.")
36
+ super().__init__(precision=precision, asdecimal=asdecimal, **kw)
37
+ self.scale = scale
38
+
39
+
40
+ class _IntegerType(_NumericCommonType, sqltypes.Integer):
41
+ def __init__(self, display_width=None, **kw):
42
+ self.display_width = display_width
43
+ super().__init__(**kw)
44
+
45
+
46
+ class _StringType(sqltypes.String):
47
+ """Base for MySQL string types."""
48
+
49
+ def __init__(
50
+ self,
51
+ charset=None,
52
+ collation=None,
53
+ ascii=False, # noqa
54
+ binary=False,
55
+ unicode=False,
56
+ national=False,
57
+ **kw,
58
+ ):
59
+ self.charset = charset
60
+
61
+ # allow collate= or collation=
62
+ kw.setdefault("collation", kw.pop("collate", collation))
63
+
64
+ self.ascii = ascii
65
+ self.unicode = unicode
66
+ self.binary = binary
67
+ self.national = national
68
+ super().__init__(**kw)
69
+
70
+
71
+ class NUMERIC(_NumericType, sqltypes.NUMERIC):
72
+ """MySQL NUMERIC type."""
73
+
74
+ __visit_name__ = "NUMERIC"
75
+
76
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
77
+ """Construct a NUMERIC.
78
+
79
+ :param precision: Total digits in this number. If scale and precision
80
+ are both None, values are stored to limits allowed by the server.
81
+
82
+ :param scale: The number of digits after the decimal point.
83
+
84
+ :param unsigned: a boolean, optional.
85
+
86
+ :param zerofill: Optional. If true, values will be stored as strings
87
+ left-padded with zeros. Note that this does not effect the values
88
+ returned by the underlying database API, which continue to be
89
+ numeric.
90
+
91
+ """
92
+ super().__init__(precision=precision, scale=scale, asdecimal=asdecimal, **kw)
93
+
94
+
95
+ class DECIMAL(_NumericType, sqltypes.DECIMAL):
96
+ """MySQL DECIMAL type."""
97
+
98
+ __visit_name__ = "DECIMAL"
99
+
100
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
101
+ """Construct a DECIMAL.
102
+
103
+ :param precision: Total digits in this number. If scale and precision
104
+ are both None, values are stored to limits allowed by the server.
105
+
106
+ :param scale: The number of digits after the decimal point.
107
+
108
+ :param unsigned: a boolean, optional.
109
+
110
+ :param zerofill: Optional. If true, values will be stored as strings
111
+ left-padded with zeros. Note that this does not effect the values
112
+ returned by the underlying database API, which continue to be
113
+ numeric.
114
+
115
+ """
116
+ super().__init__(precision=precision, scale=scale, asdecimal=asdecimal, **kw)
117
+
118
+
119
+ class DOUBLE(_FloatType, sqltypes.DOUBLE):
120
+ """MySQL DOUBLE type."""
121
+
122
+ __visit_name__ = "DOUBLE"
123
+
124
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
125
+ """Construct a DOUBLE.
126
+
127
+ .. note::
128
+
129
+ The :class:`.DOUBLE` type by default converts from float
130
+ to Decimal, using a truncation that defaults to 10 digits.
131
+ Specify either ``scale=n`` or ``decimal_return_scale=n`` in order
132
+ to change this scale, or ``asdecimal=False`` to return values
133
+ directly as Python floating points.
134
+
135
+ :param precision: Total digits in this number. If scale and precision
136
+ are both None, values are stored to limits allowed by the server.
137
+
138
+ :param scale: The number of digits after the decimal point.
139
+
140
+ :param unsigned: a boolean, optional.
141
+
142
+ :param zerofill: Optional. If true, values will be stored as strings
143
+ left-padded with zeros. Note that this does not effect the values
144
+ returned by the underlying database API, which continue to be
145
+ numeric.
146
+
147
+ """
148
+ super().__init__(precision=precision, scale=scale, asdecimal=asdecimal, **kw)
149
+
150
+
151
+ class REAL(_FloatType, sqltypes.REAL):
152
+ """MySQL REAL type."""
153
+
154
+ __visit_name__ = "REAL"
155
+
156
+ def __init__(self, precision=None, scale=None, asdecimal=True, **kw):
157
+ """Construct a REAL.
158
+
159
+ .. note::
160
+
161
+ The :class:`.REAL` type by default converts from float
162
+ to Decimal, using a truncation that defaults to 10 digits.
163
+ Specify either ``scale=n`` or ``decimal_return_scale=n`` in order
164
+ to change this scale, or ``asdecimal=False`` to return values
165
+ directly as Python floating points.
166
+
167
+ :param precision: Total digits in this number. If scale and precision
168
+ are both None, values are stored to limits allowed by the server.
169
+
170
+ :param scale: The number of digits after the decimal point.
171
+
172
+ :param unsigned: a boolean, optional.
173
+
174
+ :param zerofill: Optional. If true, values will be stored as strings
175
+ left-padded with zeros. Note that this does not effect the values
176
+ returned by the underlying database API, which continue to be
177
+ numeric.
178
+
179
+ """
180
+ super().__init__(precision=precision, scale=scale, asdecimal=asdecimal, **kw)
181
+
182
+
183
+ class FLOAT(_FloatType, sqltypes.FLOAT):
184
+ """MySQL FLOAT type."""
185
+
186
+ __visit_name__ = "FLOAT"
187
+
188
+ def __init__(self, precision=None, scale=None, asdecimal=False, **kw):
189
+ """Construct a FLOAT.
190
+
191
+ :param precision: Total digits in this number. If scale and precision
192
+ are both None, values are stored to limits allowed by the server.
193
+
194
+ :param scale: The number of digits after the decimal point.
195
+
196
+ :param unsigned: a boolean, optional.
197
+
198
+ :param zerofill: Optional. If true, values will be stored as strings
199
+ left-padded with zeros. Note that this does not effect the values
200
+ returned by the underlying database API, which continue to be
201
+ numeric.
202
+
203
+ """
204
+ super().__init__(precision=precision, scale=scale, asdecimal=asdecimal, **kw)
205
+
206
+ def bind_processor(self, dialect):
207
+ return None
208
+
209
+
210
+ class INTEGER(_IntegerType, sqltypes.INTEGER):
211
+ """MySQL INTEGER type."""
212
+
213
+ __visit_name__ = "INTEGER"
214
+
215
+ def __init__(self, display_width=None, **kw):
216
+ """Construct an INTEGER.
217
+
218
+ :param display_width: Optional, maximum display width for this number.
219
+
220
+ :param unsigned: a boolean, optional.
221
+
222
+ :param zerofill: Optional. If true, values will be stored as strings
223
+ left-padded with zeros. Note that this does not effect the values
224
+ returned by the underlying database API, which continue to be
225
+ numeric.
226
+
227
+ """
228
+ super().__init__(display_width=display_width, **kw)
229
+
230
+
231
+ class BIGINT(_IntegerType, sqltypes.BIGINT):
232
+ """MySQL BIGINTEGER type."""
233
+
234
+ __visit_name__ = "BIGINT"
235
+
236
+ def __init__(self, display_width=None, **kw):
237
+ """Construct a BIGINTEGER.
238
+
239
+ :param display_width: Optional, maximum display width for this number.
240
+
241
+ :param unsigned: a boolean, optional.
242
+
243
+ :param zerofill: Optional. If true, values will be stored as strings
244
+ left-padded with zeros. Note that this does not effect the values
245
+ returned by the underlying database API, which continue to be
246
+ numeric.
247
+
248
+ """
249
+ super().__init__(display_width=display_width, **kw)
250
+
251
+
252
+ class MEDIUMINT(_IntegerType):
253
+ """MySQL MEDIUMINTEGER type."""
254
+
255
+ __visit_name__ = "MEDIUMINT"
256
+
257
+ def __init__(self, display_width=None, **kw):
258
+ """Construct a MEDIUMINTEGER
259
+
260
+ :param display_width: Optional, maximum display width for this number.
261
+
262
+ :param unsigned: a boolean, optional.
263
+
264
+ :param zerofill: Optional. If true, values will be stored as strings
265
+ left-padded with zeros. Note that this does not effect the values
266
+ returned by the underlying database API, which continue to be
267
+ numeric.
268
+
269
+ """
270
+ super().__init__(display_width=display_width, **kw)
271
+
272
+
273
+ class TINYINT(_IntegerType):
274
+ """MySQL TINYINT type."""
275
+
276
+ __visit_name__ = "TINYINT"
277
+
278
+ def __init__(self, display_width=None, **kw):
279
+ """Construct a TINYINT.
280
+
281
+ :param display_width: Optional, maximum display width for this number.
282
+
283
+ :param unsigned: a boolean, optional.
284
+
285
+ :param zerofill: Optional. If true, values will be stored as strings
286
+ left-padded with zeros. Note that this does not effect the values
287
+ returned by the underlying database API, which continue to be
288
+ numeric.
289
+
290
+ """
291
+ super().__init__(display_width=display_width, **kw)
292
+
293
+
294
+ class SMALLINT(_IntegerType, sqltypes.SMALLINT):
295
+ """MySQL SMALLINTEGER type."""
296
+
297
+ __visit_name__ = "SMALLINT"
298
+
299
+ def __init__(self, display_width=None, **kw):
300
+ """Construct a SMALLINTEGER.
301
+
302
+ :param display_width: Optional, maximum display width for this number.
303
+
304
+ :param unsigned: a boolean, optional.
305
+
306
+ :param zerofill: Optional. If true, values will be stored as strings
307
+ left-padded with zeros. Note that this does not effect the values
308
+ returned by the underlying database API, which continue to be
309
+ numeric.
310
+
311
+ """
312
+ super().__init__(display_width=display_width, **kw)
313
+
314
+
315
+ class BIT(sqltypes.TypeEngine):
316
+ """MySQL BIT type.
317
+
318
+ This type is for MySQL 5.0.3 or greater for MyISAM, and 5.0.5 or greater
319
+ for MyISAM, MEMORY, InnoDB and BDB. For older versions, use a
320
+ MSTinyInteger() type.
321
+
322
+ """
323
+
324
+ __visit_name__ = "BIT"
325
+
326
+ def __init__(self, length=None):
327
+ """Construct a BIT.
328
+
329
+ :param length: Optional, number of bits.
330
+
331
+ """
332
+ self.length = length
333
+
334
+ def result_processor(self, dialect, coltype):
335
+ """Convert a MySQL's 64 bit, variable length binary string to a long.
336
+
337
+ TODO: this is MySQL-db, pyodbc specific. OurSQL and mysqlconnector
338
+ already do this, so this logic should be moved to those dialects.
339
+
340
+ """
341
+
342
+ def process(value):
343
+ if value is not None:
344
+ v = 0
345
+ for i in value:
346
+ if not isinstance(i, int):
347
+ i = ord(i) # convert byte to int on Python 2
348
+ v = v << 8 | i
349
+ return v
350
+ return value
351
+
352
+ return process
353
+
354
+
355
+ class TIME(sqltypes.TIME):
356
+ """MySQL TIME type."""
357
+
358
+ __visit_name__ = "TIME"
359
+
360
+ def __init__(self, timezone=False, fsp=None):
361
+ """Construct a MySQL TIME type.
362
+
363
+ :param timezone: not used by the MySQL dialect.
364
+ :param fsp: fractional seconds precision value.
365
+ MySQL 5.6 supports storage of fractional seconds;
366
+ this parameter will be used when emitting DDL
367
+ for the TIME type.
368
+
369
+ .. note::
370
+
371
+ DBAPI driver support for fractional seconds may
372
+ be limited; current support includes
373
+ MySQL Connector/Python.
374
+
375
+ """
376
+ super().__init__(timezone=timezone)
377
+ self.fsp = fsp
378
+
379
+ def result_processor(self, dialect, coltype):
380
+ time = datetime.time
381
+
382
+ def process(value):
383
+ # convert from a timedelta value
384
+ if value is not None:
385
+ microseconds = value.microseconds
386
+ seconds = value.seconds
387
+ minutes = seconds // 60
388
+ return time(
389
+ minutes // 60,
390
+ minutes % 60,
391
+ seconds - minutes * 60,
392
+ microsecond=microseconds,
393
+ )
394
+ else:
395
+ return None
396
+
397
+ return process
398
+
399
+
400
+ class TIMESTAMP(sqltypes.TIMESTAMP):
401
+ """MySQL TIMESTAMP type."""
402
+
403
+ __visit_name__ = "TIMESTAMP"
404
+
405
+ def __init__(self, timezone=False, fsp=None):
406
+ """Construct a MySQL TIMESTAMP type.
407
+
408
+ :param timezone: not used by the MySQL dialect.
409
+ :param fsp: fractional seconds precision value.
410
+ MySQL 5.6.4 supports storage of fractional seconds;
411
+ this parameter will be used when emitting DDL
412
+ for the TIMESTAMP type.
413
+
414
+ .. note::
415
+
416
+ DBAPI driver support for fractional seconds may
417
+ be limited; current support includes
418
+ MySQL Connector/Python.
419
+
420
+ """
421
+ super().__init__(timezone=timezone)
422
+ self.fsp = fsp
423
+
424
+
425
+ class DATETIME(sqltypes.DATETIME):
426
+ """MySQL DATETIME type."""
427
+
428
+ __visit_name__ = "DATETIME"
429
+
430
+ def __init__(self, timezone=False, fsp=None):
431
+ """Construct a MySQL DATETIME type.
432
+
433
+ :param timezone: not used by the MySQL dialect.
434
+ :param fsp: fractional seconds precision value.
435
+ MySQL 5.6.4 supports storage of fractional seconds;
436
+ this parameter will be used when emitting DDL
437
+ for the DATETIME type.
438
+
439
+ .. note::
440
+
441
+ DBAPI driver support for fractional seconds may
442
+ be limited; current support includes
443
+ MySQL Connector/Python.
444
+
445
+ """
446
+ super().__init__(timezone=timezone)
447
+ self.fsp = fsp
448
+
449
+
450
+ class YEAR(sqltypes.TypeEngine):
451
+ """MySQL YEAR type, for single byte storage of years 1901-2155."""
452
+
453
+ __visit_name__ = "YEAR"
454
+
455
+ def __init__(self, display_width=None):
456
+ self.display_width = display_width
457
+
458
+
459
+ class TEXT(_StringType, sqltypes.TEXT):
460
+ """MySQL TEXT type, for character storage encoded up to 2^16 bytes."""
461
+
462
+ __visit_name__ = "TEXT"
463
+
464
+ def __init__(self, length=None, **kw):
465
+ """Construct a TEXT.
466
+
467
+ :param length: Optional, if provided the server may optimize storage
468
+ by substituting the smallest TEXT type sufficient to store
469
+ ``length`` bytes of characters.
470
+
471
+ :param charset: Optional, a column-level character set for this string
472
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
473
+
474
+ :param collation: Optional, a column-level collation for this string
475
+ value. Takes precedence to 'binary' short-hand.
476
+
477
+ :param ascii: Defaults to False: short-hand for the ``latin1``
478
+ character set, generates ASCII in schema.
479
+
480
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
481
+ character set, generates UNICODE in schema.
482
+
483
+ :param national: Optional. If true, use the server's configured
484
+ national character set.
485
+
486
+ :param binary: Defaults to False: short-hand, pick the binary
487
+ collation type that matches the column's character set. Generates
488
+ BINARY in schema. This does not affect the type of data stored,
489
+ only the collation of character data.
490
+
491
+ """
492
+ super().__init__(length=length, **kw)
493
+
494
+
495
+ class TINYTEXT(_StringType):
496
+ """MySQL TINYTEXT type, for character storage encoded up to 2^8 bytes."""
497
+
498
+ __visit_name__ = "TINYTEXT"
499
+
500
+ def __init__(self, **kwargs):
501
+ """Construct a TINYTEXT.
502
+
503
+ :param charset: Optional, a column-level character set for this string
504
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
505
+
506
+ :param collation: Optional, a column-level collation for this string
507
+ value. Takes precedence to 'binary' short-hand.
508
+
509
+ :param ascii: Defaults to False: short-hand for the ``latin1``
510
+ character set, generates ASCII in schema.
511
+
512
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
513
+ character set, generates UNICODE in schema.
514
+
515
+ :param national: Optional. If true, use the server's configured
516
+ national character set.
517
+
518
+ :param binary: Defaults to False: short-hand, pick the binary
519
+ collation type that matches the column's character set. Generates
520
+ BINARY in schema. This does not affect the type of data stored,
521
+ only the collation of character data.
522
+
523
+ """
524
+ super().__init__(**kwargs)
525
+
526
+
527
+ class MEDIUMTEXT(_StringType):
528
+ """MySQL MEDIUMTEXT type, for character storage encoded up
529
+ to 2^24 bytes."""
530
+
531
+ __visit_name__ = "MEDIUMTEXT"
532
+
533
+ def __init__(self, **kwargs):
534
+ """Construct a MEDIUMTEXT.
535
+
536
+ :param charset: Optional, a column-level character set for this string
537
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
538
+
539
+ :param collation: Optional, a column-level collation for this string
540
+ value. Takes precedence to 'binary' short-hand.
541
+
542
+ :param ascii: Defaults to False: short-hand for the ``latin1``
543
+ character set, generates ASCII in schema.
544
+
545
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
546
+ character set, generates UNICODE in schema.
547
+
548
+ :param national: Optional. If true, use the server's configured
549
+ national character set.
550
+
551
+ :param binary: Defaults to False: short-hand, pick the binary
552
+ collation type that matches the column's character set. Generates
553
+ BINARY in schema. This does not affect the type of data stored,
554
+ only the collation of character data.
555
+
556
+ """
557
+ super().__init__(**kwargs)
558
+
559
+
560
+ class LONGTEXT(_StringType):
561
+ """MySQL LONGTEXT type, for character storage encoded up to 2^32 bytes."""
562
+
563
+ __visit_name__ = "LONGTEXT"
564
+
565
+ def __init__(self, **kwargs):
566
+ """Construct a LONGTEXT.
567
+
568
+ :param charset: Optional, a column-level character set for this string
569
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
570
+
571
+ :param collation: Optional, a column-level collation for this string
572
+ value. Takes precedence to 'binary' short-hand.
573
+
574
+ :param ascii: Defaults to False: short-hand for the ``latin1``
575
+ character set, generates ASCII in schema.
576
+
577
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
578
+ character set, generates UNICODE in schema.
579
+
580
+ :param national: Optional. If true, use the server's configured
581
+ national character set.
582
+
583
+ :param binary: Defaults to False: short-hand, pick the binary
584
+ collation type that matches the column's character set. Generates
585
+ BINARY in schema. This does not affect the type of data stored,
586
+ only the collation of character data.
587
+
588
+ """
589
+ super().__init__(**kwargs)
590
+
591
+
592
+ class VARCHAR(_StringType, sqltypes.VARCHAR):
593
+ """MySQL VARCHAR type, for variable-length character data."""
594
+
595
+ __visit_name__ = "VARCHAR"
596
+
597
+ def __init__(self, length=None, **kwargs):
598
+ """Construct a VARCHAR.
599
+
600
+ :param charset: Optional, a column-level character set for this string
601
+ value. Takes precedence to 'ascii' or 'unicode' short-hand.
602
+
603
+ :param collation: Optional, a column-level collation for this string
604
+ value. Takes precedence to 'binary' short-hand.
605
+
606
+ :param ascii: Defaults to False: short-hand for the ``latin1``
607
+ character set, generates ASCII in schema.
608
+
609
+ :param unicode: Defaults to False: short-hand for the ``ucs2``
610
+ character set, generates UNICODE in schema.
611
+
612
+ :param national: Optional. If true, use the server's configured
613
+ national character set.
614
+
615
+ :param binary: Defaults to False: short-hand, pick the binary
616
+ collation type that matches the column's character set. Generates
617
+ BINARY in schema. This does not affect the type of data stored,
618
+ only the collation of character data.
619
+
620
+ """
621
+ super().__init__(length=length, **kwargs)
622
+
623
+
624
+ class CHAR(_StringType, sqltypes.CHAR):
625
+ """MySQL CHAR type, for fixed-length character data."""
626
+
627
+ __visit_name__ = "CHAR"
628
+
629
+ def __init__(self, length=None, **kwargs):
630
+ """Construct a CHAR.
631
+
632
+ :param length: Maximum data length, in characters.
633
+
634
+ :param binary: Optional, use the default binary collation for the
635
+ national character set. This does not affect the type of data
636
+ stored, use a BINARY type for binary data.
637
+
638
+ :param collation: Optional, request a particular collation. Must be
639
+ compatible with the national character set.
640
+
641
+ """
642
+ super().__init__(length=length, **kwargs)
643
+
644
+ @classmethod
645
+ def _adapt_string_for_cast(cls, type_):
646
+ # copy the given string type into a CHAR
647
+ # for the purposes of rendering a CAST expression
648
+ type_ = sqltypes.to_instance(type_)
649
+ if isinstance(type_, sqltypes.CHAR):
650
+ return type_
651
+ elif isinstance(type_, _StringType):
652
+ return CHAR(
653
+ length=type_.length,
654
+ charset=type_.charset,
655
+ collation=type_.collation,
656
+ ascii=type_.ascii,
657
+ binary=type_.binary,
658
+ unicode=type_.unicode,
659
+ national=False, # not supported in CAST
660
+ )
661
+ else:
662
+ return CHAR(length=type_.length)
663
+
664
+
665
+ class NVARCHAR(_StringType, sqltypes.NVARCHAR):
666
+ """MySQL NVARCHAR type.
667
+
668
+ For variable-length character data in the server's configured national
669
+ character set.
670
+ """
671
+
672
+ __visit_name__ = "NVARCHAR"
673
+
674
+ def __init__(self, length=None, **kwargs):
675
+ """Construct an NVARCHAR.
676
+
677
+ :param length: Maximum data length, in characters.
678
+
679
+ :param binary: Optional, use the default binary collation for the
680
+ national character set. This does not affect the type of data
681
+ stored, use a BINARY type for binary data.
682
+
683
+ :param collation: Optional, request a particular collation. Must be
684
+ compatible with the national character set.
685
+
686
+ """
687
+ kwargs["national"] = True
688
+ super().__init__(length=length, **kwargs)
689
+
690
+
691
+ class NCHAR(_StringType, sqltypes.NCHAR):
692
+ """MySQL NCHAR type.
693
+
694
+ For fixed-length character data in the server's configured national
695
+ character set.
696
+ """
697
+
698
+ __visit_name__ = "NCHAR"
699
+
700
+ def __init__(self, length=None, **kwargs):
701
+ """Construct an NCHAR.
702
+
703
+ :param length: Maximum data length, in characters.
704
+
705
+ :param binary: Optional, use the default binary collation for the
706
+ national character set. This does not affect the type of data
707
+ stored, use a BINARY type for binary data.
708
+
709
+ :param collation: Optional, request a particular collation. Must be
710
+ compatible with the national character set.
711
+
712
+ """
713
+ kwargs["national"] = True
714
+ super().__init__(length=length, **kwargs)
715
+
716
+
717
+ class TINYBLOB(sqltypes._Binary):
718
+ """MySQL TINYBLOB type, for binary data up to 2^8 bytes."""
719
+
720
+ __visit_name__ = "TINYBLOB"
721
+
722
+
723
+ class MEDIUMBLOB(sqltypes._Binary):
724
+ """MySQL MEDIUMBLOB type, for binary data up to 2^24 bytes."""
725
+
726
+ __visit_name__ = "MEDIUMBLOB"
727
+
728
+
729
+ class LONGBLOB(sqltypes._Binary):
730
+ """MySQL LONGBLOB type, for binary data up to 2^32 bytes."""
731
+
732
+ __visit_name__ = "LONGBLOB"