ormlambda 3.11.2__py3-none-any.whl → 3.34.0__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.
- ormlambda/__init__.py +3 -1
- ormlambda/caster/__init__.py +1 -1
- ormlambda/caster/caster.py +29 -12
- ormlambda/common/abstract_classes/clause_info_converter.py +65 -0
- ormlambda/common/abstract_classes/decomposition_query.py +27 -68
- ormlambda/common/abstract_classes/non_query_base.py +10 -8
- ormlambda/common/abstract_classes/query_base.py +3 -1
- ormlambda/common/errors/__init__.py +29 -0
- ormlambda/common/interfaces/ICustomAlias.py +1 -1
- ormlambda/common/interfaces/IQueryCommand.py +6 -2
- ormlambda/dialects/__init__.py +39 -0
- ormlambda/dialects/default/__init__.py +1 -0
- ormlambda/dialects/default/base.py +39 -0
- ormlambda/dialects/interface/__init__.py +1 -0
- ormlambda/dialects/interface/dialect.py +78 -0
- ormlambda/dialects/mysql/__init__.py +38 -0
- ormlambda/dialects/mysql/base.py +388 -0
- ormlambda/dialects/mysql/caster/caster.py +39 -0
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/__init__.py +1 -0
- ormlambda/dialects/mysql/caster/types/boolean.py +35 -0
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/bytes.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/datetime.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/float.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/int.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/iterable.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/none.py +8 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/point.py +4 -4
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/string.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/clauses/ST_AsText.py +8 -7
- ormlambda/{databases/my_sql → dialects/mysql}/clauses/ST_Contains.py +10 -5
- ormlambda/dialects/mysql/clauses/__init__.py +13 -0
- ormlambda/dialects/mysql/clauses/count.py +33 -0
- ormlambda/dialects/mysql/clauses/delete.py +9 -0
- ormlambda/dialects/mysql/clauses/group_by.py +17 -0
- ormlambda/dialects/mysql/clauses/having.py +12 -0
- ormlambda/dialects/mysql/clauses/insert.py +9 -0
- ormlambda/dialects/mysql/clauses/joins.py +14 -0
- ormlambda/dialects/mysql/clauses/limit.py +6 -0
- ormlambda/dialects/mysql/clauses/offset.py +6 -0
- ormlambda/dialects/mysql/clauses/order.py +8 -0
- ormlambda/dialects/mysql/clauses/update.py +8 -0
- ormlambda/dialects/mysql/clauses/upsert.py +9 -0
- ormlambda/dialects/mysql/clauses/where.py +7 -0
- ormlambda/dialects/mysql/mysqlconnector.py +46 -0
- ormlambda/dialects/mysql/repository/__init__.py +1 -0
- ormlambda/dialects/mysql/repository/repository.py +212 -0
- ormlambda/dialects/mysql/types.py +732 -0
- ormlambda/dialects/sqlite/__init__.py +5 -0
- ormlambda/dialects/sqlite/base.py +47 -0
- ormlambda/dialects/sqlite/pysqlite.py +32 -0
- ormlambda/engine/__init__.py +1 -0
- ormlambda/engine/base.py +77 -0
- ormlambda/engine/create.py +9 -23
- ormlambda/engine/url.py +34 -19
- ormlambda/env.py +30 -0
- ormlambda/errors.py +17 -0
- ormlambda/model/base_model.py +7 -9
- ormlambda/repository/base_repository.py +36 -5
- ormlambda/repository/interfaces/IRepositoryBase.py +119 -12
- ormlambda/repository/response.py +134 -0
- ormlambda/sql/clause_info/__init__.py +2 -1
- ormlambda/sql/clause_info/aggregate_function_base.py +96 -0
- ormlambda/sql/clause_info/clause_info.py +35 -115
- ormlambda/sql/clause_info/interface/IClauseInfo.py +37 -0
- ormlambda/sql/clause_info/interface/__init__.py +1 -0
- ormlambda/sql/clauses/__init__.py +14 -0
- ormlambda/{databases/my_sql → sql}/clauses/alias.py +23 -6
- ormlambda/{databases/my_sql → sql}/clauses/count.py +15 -1
- ormlambda/{databases/my_sql → sql}/clauses/delete.py +22 -7
- ormlambda/sql/clauses/group_by.py +30 -0
- ormlambda/{databases/my_sql → sql}/clauses/having.py +7 -2
- ormlambda/{databases/my_sql → sql}/clauses/insert.py +16 -9
- ormlambda/sql/clauses/interfaces/__init__.py +5 -0
- ormlambda/sql/clauses/join/__init__.py +1 -0
- ormlambda/{databases/my_sql → sql/clauses/join}/join_context.py +15 -7
- ormlambda/{databases/my_sql → sql}/clauses/joins.py +29 -19
- ormlambda/sql/clauses/limit.py +15 -0
- ormlambda/sql/clauses/offset.py +15 -0
- ormlambda/{databases/my_sql → sql}/clauses/order.py +14 -24
- ormlambda/{databases/my_sql → sql}/clauses/select.py +14 -13
- ormlambda/{databases/my_sql → sql}/clauses/update.py +24 -11
- ormlambda/{databases/my_sql → sql}/clauses/upsert.py +19 -10
- ormlambda/{databases/my_sql → sql}/clauses/where.py +28 -8
- ormlambda/sql/column/__init__.py +1 -0
- ormlambda/sql/{column.py → column/column.py} +85 -22
- ormlambda/sql/comparer.py +51 -37
- ormlambda/sql/compiler.py +668 -0
- ormlambda/sql/ddl.py +82 -0
- ormlambda/sql/elements.py +36 -0
- ormlambda/sql/foreign_key.py +61 -39
- ormlambda/{databases/my_sql → sql}/functions/concat.py +13 -5
- ormlambda/{databases/my_sql → sql}/functions/max.py +9 -4
- ormlambda/{databases/my_sql → sql}/functions/min.py +9 -13
- ormlambda/{databases/my_sql → sql}/functions/sum.py +8 -10
- ormlambda/sql/sqltypes.py +647 -0
- ormlambda/sql/table/__init__.py +1 -1
- ormlambda/sql/table/table.py +175 -0
- ormlambda/sql/table/table_constructor.py +1 -208
- ormlambda/sql/type_api.py +35 -0
- ormlambda/sql/types.py +3 -1
- ormlambda/sql/visitors.py +74 -0
- ormlambda/statements/__init__.py +1 -0
- ormlambda/statements/base_statement.py +34 -40
- ormlambda/statements/interfaces/IStatements.py +28 -21
- ormlambda/statements/query_builder.py +163 -0
- ormlambda/{databases/my_sql → statements}/statements.py +68 -210
- ormlambda/statements/types.py +2 -2
- ormlambda/types/__init__.py +24 -0
- ormlambda/types/metadata.py +42 -0
- ormlambda/util/__init__.py +87 -0
- ormlambda/{utils → util}/module_tree/dynamic_module.py +4 -3
- ormlambda/util/plugin_loader.py +32 -0
- ormlambda/util/typing.py +6 -0
- ormlambda-3.34.0.dist-info/AUTHORS +32 -0
- {ormlambda-3.11.2.dist-info → ormlambda-3.34.0.dist-info}/METADATA +56 -10
- ormlambda-3.34.0.dist-info/RECORD +152 -0
- ormlambda/components/__init__.py +0 -4
- ormlambda/components/delete/__init__.py +0 -2
- ormlambda/components/delete/abstract_delete.py +0 -17
- ormlambda/components/insert/__init__.py +0 -2
- ormlambda/components/insert/abstract_insert.py +0 -25
- ormlambda/components/select/__init__.py +0 -1
- ormlambda/components/update/__init__.py +0 -2
- ormlambda/components/update/abstract_update.py +0 -29
- ormlambda/components/upsert/__init__.py +0 -2
- ormlambda/components/upsert/abstract_upsert.py +0 -25
- ormlambda/databases/__init__.py +0 -5
- ormlambda/databases/my_sql/__init__.py +0 -4
- ormlambda/databases/my_sql/caster/caster.py +0 -39
- ormlambda/databases/my_sql/clauses/__init__.py +0 -20
- ormlambda/databases/my_sql/clauses/create_database.py +0 -35
- ormlambda/databases/my_sql/clauses/drop_database.py +0 -17
- ormlambda/databases/my_sql/clauses/drop_table.py +0 -23
- ormlambda/databases/my_sql/clauses/group_by.py +0 -31
- ormlambda/databases/my_sql/clauses/limit.py +0 -17
- ormlambda/databases/my_sql/clauses/offset.py +0 -17
- ormlambda/databases/my_sql/repository/__init__.py +0 -1
- ormlambda/databases/my_sql/repository/repository.py +0 -351
- ormlambda/engine/template.py +0 -47
- ormlambda/sql/dtypes.py +0 -94
- ormlambda/utils/__init__.py +0 -1
- ormlambda-3.11.2.dist-info/RECORD +0 -120
- /ormlambda/{databases/my_sql → dialects/mysql}/caster/__init__.py +0 -0
- /ormlambda/{databases/my_sql/types.py → dialects/mysql/repository/pool_types.py} +0 -0
- /ormlambda/{components/delete → sql/clauses/interfaces}/IDelete.py +0 -0
- /ormlambda/{components/insert → sql/clauses/interfaces}/IInsert.py +0 -0
- /ormlambda/{components/select → sql/clauses/interfaces}/ISelect.py +0 -0
- /ormlambda/{components/update → sql/clauses/interfaces}/IUpdate.py +0 -0
- /ormlambda/{components/upsert → sql/clauses/interfaces}/IUpsert.py +0 -0
- /ormlambda/{databases/my_sql → sql}/functions/__init__.py +0 -0
- /ormlambda/{utils → util}/module_tree/__init__.py +0 -0
- /ormlambda/{utils → util}/module_tree/dfs_traversal.py +0 -0
- {ormlambda-3.11.2.dist-info → ormlambda-3.34.0.dist-info}/LICENSE +0 -0
- {ormlambda-3.11.2.dist-info → ormlambda-3.34.0.dist-info}/WHEEL +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"
|