singlestoredb 1.16.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 (183) hide show
  1. singlestoredb/__init__.py +75 -0
  2. singlestoredb/ai/__init__.py +2 -0
  3. singlestoredb/ai/chat.py +139 -0
  4. singlestoredb/ai/embeddings.py +128 -0
  5. singlestoredb/alchemy/__init__.py +90 -0
  6. singlestoredb/apps/__init__.py +3 -0
  7. singlestoredb/apps/_cloud_functions.py +90 -0
  8. singlestoredb/apps/_config.py +72 -0
  9. singlestoredb/apps/_connection_info.py +18 -0
  10. singlestoredb/apps/_dashboards.py +47 -0
  11. singlestoredb/apps/_process.py +32 -0
  12. singlestoredb/apps/_python_udfs.py +100 -0
  13. singlestoredb/apps/_stdout_supress.py +30 -0
  14. singlestoredb/apps/_uvicorn_util.py +36 -0
  15. singlestoredb/auth.py +245 -0
  16. singlestoredb/config.py +484 -0
  17. singlestoredb/connection.py +1487 -0
  18. singlestoredb/converters.py +950 -0
  19. singlestoredb/docstring/__init__.py +33 -0
  20. singlestoredb/docstring/attrdoc.py +126 -0
  21. singlestoredb/docstring/common.py +230 -0
  22. singlestoredb/docstring/epydoc.py +267 -0
  23. singlestoredb/docstring/google.py +412 -0
  24. singlestoredb/docstring/numpydoc.py +562 -0
  25. singlestoredb/docstring/parser.py +100 -0
  26. singlestoredb/docstring/py.typed +1 -0
  27. singlestoredb/docstring/rest.py +256 -0
  28. singlestoredb/docstring/tests/__init__.py +1 -0
  29. singlestoredb/docstring/tests/_pydoctor.py +21 -0
  30. singlestoredb/docstring/tests/test_epydoc.py +729 -0
  31. singlestoredb/docstring/tests/test_google.py +1007 -0
  32. singlestoredb/docstring/tests/test_numpydoc.py +1100 -0
  33. singlestoredb/docstring/tests/test_parse_from_object.py +109 -0
  34. singlestoredb/docstring/tests/test_parser.py +248 -0
  35. singlestoredb/docstring/tests/test_rest.py +547 -0
  36. singlestoredb/docstring/tests/test_util.py +70 -0
  37. singlestoredb/docstring/util.py +141 -0
  38. singlestoredb/exceptions.py +120 -0
  39. singlestoredb/functions/__init__.py +16 -0
  40. singlestoredb/functions/decorator.py +201 -0
  41. singlestoredb/functions/dtypes.py +1793 -0
  42. singlestoredb/functions/ext/__init__.py +1 -0
  43. singlestoredb/functions/ext/arrow.py +375 -0
  44. singlestoredb/functions/ext/asgi.py +2133 -0
  45. singlestoredb/functions/ext/json.py +420 -0
  46. singlestoredb/functions/ext/mmap.py +413 -0
  47. singlestoredb/functions/ext/rowdat_1.py +724 -0
  48. singlestoredb/functions/ext/timer.py +89 -0
  49. singlestoredb/functions/ext/utils.py +218 -0
  50. singlestoredb/functions/signature.py +1578 -0
  51. singlestoredb/functions/typing/__init__.py +41 -0
  52. singlestoredb/functions/typing/numpy.py +20 -0
  53. singlestoredb/functions/typing/pandas.py +2 -0
  54. singlestoredb/functions/typing/polars.py +2 -0
  55. singlestoredb/functions/typing/pyarrow.py +2 -0
  56. singlestoredb/functions/utils.py +421 -0
  57. singlestoredb/fusion/__init__.py +11 -0
  58. singlestoredb/fusion/graphql.py +213 -0
  59. singlestoredb/fusion/handler.py +916 -0
  60. singlestoredb/fusion/handlers/__init__.py +0 -0
  61. singlestoredb/fusion/handlers/export.py +525 -0
  62. singlestoredb/fusion/handlers/files.py +690 -0
  63. singlestoredb/fusion/handlers/job.py +660 -0
  64. singlestoredb/fusion/handlers/models.py +250 -0
  65. singlestoredb/fusion/handlers/stage.py +502 -0
  66. singlestoredb/fusion/handlers/utils.py +324 -0
  67. singlestoredb/fusion/handlers/workspace.py +956 -0
  68. singlestoredb/fusion/registry.py +249 -0
  69. singlestoredb/fusion/result.py +399 -0
  70. singlestoredb/http/__init__.py +27 -0
  71. singlestoredb/http/connection.py +1267 -0
  72. singlestoredb/magics/__init__.py +34 -0
  73. singlestoredb/magics/run_personal.py +137 -0
  74. singlestoredb/magics/run_shared.py +134 -0
  75. singlestoredb/management/__init__.py +9 -0
  76. singlestoredb/management/billing_usage.py +148 -0
  77. singlestoredb/management/cluster.py +462 -0
  78. singlestoredb/management/export.py +295 -0
  79. singlestoredb/management/files.py +1102 -0
  80. singlestoredb/management/inference_api.py +105 -0
  81. singlestoredb/management/job.py +887 -0
  82. singlestoredb/management/manager.py +373 -0
  83. singlestoredb/management/organization.py +226 -0
  84. singlestoredb/management/region.py +169 -0
  85. singlestoredb/management/utils.py +423 -0
  86. singlestoredb/management/workspace.py +1927 -0
  87. singlestoredb/mysql/__init__.py +177 -0
  88. singlestoredb/mysql/_auth.py +298 -0
  89. singlestoredb/mysql/charset.py +214 -0
  90. singlestoredb/mysql/connection.py +2032 -0
  91. singlestoredb/mysql/constants/CLIENT.py +38 -0
  92. singlestoredb/mysql/constants/COMMAND.py +32 -0
  93. singlestoredb/mysql/constants/CR.py +78 -0
  94. singlestoredb/mysql/constants/ER.py +474 -0
  95. singlestoredb/mysql/constants/EXTENDED_TYPE.py +3 -0
  96. singlestoredb/mysql/constants/FIELD_TYPE.py +48 -0
  97. singlestoredb/mysql/constants/FLAG.py +15 -0
  98. singlestoredb/mysql/constants/SERVER_STATUS.py +10 -0
  99. singlestoredb/mysql/constants/VECTOR_TYPE.py +6 -0
  100. singlestoredb/mysql/constants/__init__.py +0 -0
  101. singlestoredb/mysql/converters.py +271 -0
  102. singlestoredb/mysql/cursors.py +896 -0
  103. singlestoredb/mysql/err.py +92 -0
  104. singlestoredb/mysql/optionfile.py +20 -0
  105. singlestoredb/mysql/protocol.py +450 -0
  106. singlestoredb/mysql/tests/__init__.py +19 -0
  107. singlestoredb/mysql/tests/base.py +126 -0
  108. singlestoredb/mysql/tests/conftest.py +37 -0
  109. singlestoredb/mysql/tests/test_DictCursor.py +132 -0
  110. singlestoredb/mysql/tests/test_SSCursor.py +141 -0
  111. singlestoredb/mysql/tests/test_basic.py +452 -0
  112. singlestoredb/mysql/tests/test_connection.py +851 -0
  113. singlestoredb/mysql/tests/test_converters.py +58 -0
  114. singlestoredb/mysql/tests/test_cursor.py +141 -0
  115. singlestoredb/mysql/tests/test_err.py +16 -0
  116. singlestoredb/mysql/tests/test_issues.py +514 -0
  117. singlestoredb/mysql/tests/test_load_local.py +75 -0
  118. singlestoredb/mysql/tests/test_nextset.py +88 -0
  119. singlestoredb/mysql/tests/test_optionfile.py +27 -0
  120. singlestoredb/mysql/tests/thirdparty/__init__.py +6 -0
  121. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/__init__.py +9 -0
  122. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/capabilities.py +323 -0
  123. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/dbapi20.py +865 -0
  124. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py +110 -0
  125. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py +224 -0
  126. singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py +101 -0
  127. singlestoredb/mysql/times.py +23 -0
  128. singlestoredb/notebook/__init__.py +16 -0
  129. singlestoredb/notebook/_objects.py +213 -0
  130. singlestoredb/notebook/_portal.py +352 -0
  131. singlestoredb/py.typed +0 -0
  132. singlestoredb/pytest.py +352 -0
  133. singlestoredb/server/__init__.py +0 -0
  134. singlestoredb/server/docker.py +452 -0
  135. singlestoredb/server/free_tier.py +267 -0
  136. singlestoredb/tests/__init__.py +0 -0
  137. singlestoredb/tests/alltypes.sql +307 -0
  138. singlestoredb/tests/alltypes_no_nulls.sql +208 -0
  139. singlestoredb/tests/empty.sql +0 -0
  140. singlestoredb/tests/ext_funcs/__init__.py +702 -0
  141. singlestoredb/tests/local_infile.csv +3 -0
  142. singlestoredb/tests/test.ipynb +18 -0
  143. singlestoredb/tests/test.sql +680 -0
  144. singlestoredb/tests/test2.ipynb +18 -0
  145. singlestoredb/tests/test2.sql +1 -0
  146. singlestoredb/tests/test_basics.py +1332 -0
  147. singlestoredb/tests/test_config.py +318 -0
  148. singlestoredb/tests/test_connection.py +3103 -0
  149. singlestoredb/tests/test_dbapi.py +27 -0
  150. singlestoredb/tests/test_exceptions.py +45 -0
  151. singlestoredb/tests/test_ext_func.py +1472 -0
  152. singlestoredb/tests/test_ext_func_data.py +1101 -0
  153. singlestoredb/tests/test_fusion.py +1527 -0
  154. singlestoredb/tests/test_http.py +288 -0
  155. singlestoredb/tests/test_management.py +1599 -0
  156. singlestoredb/tests/test_plugin.py +33 -0
  157. singlestoredb/tests/test_results.py +171 -0
  158. singlestoredb/tests/test_types.py +132 -0
  159. singlestoredb/tests/test_udf.py +737 -0
  160. singlestoredb/tests/test_udf_returns.py +459 -0
  161. singlestoredb/tests/test_vectorstore.py +51 -0
  162. singlestoredb/tests/test_xdict.py +333 -0
  163. singlestoredb/tests/utils.py +141 -0
  164. singlestoredb/types.py +373 -0
  165. singlestoredb/utils/__init__.py +0 -0
  166. singlestoredb/utils/config.py +950 -0
  167. singlestoredb/utils/convert_rows.py +69 -0
  168. singlestoredb/utils/debug.py +13 -0
  169. singlestoredb/utils/dtypes.py +205 -0
  170. singlestoredb/utils/events.py +65 -0
  171. singlestoredb/utils/mogrify.py +151 -0
  172. singlestoredb/utils/results.py +585 -0
  173. singlestoredb/utils/xdict.py +425 -0
  174. singlestoredb/vectorstore.py +192 -0
  175. singlestoredb/warnings.py +5 -0
  176. singlestoredb-1.16.1.dist-info/METADATA +165 -0
  177. singlestoredb-1.16.1.dist-info/RECORD +183 -0
  178. singlestoredb-1.16.1.dist-info/WHEEL +5 -0
  179. singlestoredb-1.16.1.dist-info/entry_points.txt +2 -0
  180. singlestoredb-1.16.1.dist-info/licenses/LICENSE +201 -0
  181. singlestoredb-1.16.1.dist-info/top_level.txt +3 -0
  182. sqlx/__init__.py +4 -0
  183. sqlx/magic.py +113 -0
@@ -0,0 +1,1793 @@
1
+ #!/usr/bin/env python3
2
+ import base64
3
+ import datetime
4
+ import decimal
5
+ import re
6
+ from typing import Any
7
+ from typing import Callable
8
+ from typing import Optional
9
+ from typing import Union
10
+
11
+ from ..converters import converters
12
+ from ..mysql.converters import escape_item # type: ignore
13
+ from ..utils.dtypes import DEFAULT_VALUES # noqa
14
+ from ..utils.dtypes import NUMPY_TYPE_MAP # noqa
15
+ from ..utils.dtypes import PANDAS_TYPE_MAP # noqa
16
+ from ..utils.dtypes import POLARS_TYPE_MAP # noqa
17
+ from ..utils.dtypes import PYARROW_TYPE_MAP # noqa
18
+
19
+
20
+ DataType = Union[str, Callable[..., Any]]
21
+
22
+
23
+ class SQLString(str):
24
+ """SQL string type."""
25
+ name: Optional[str] = None
26
+
27
+
28
+ class NULL:
29
+ """NULL (for use in default values)."""
30
+ pass
31
+
32
+
33
+ def escape_name(name: str) -> str:
34
+ """Escape a function parameter name."""
35
+ if '`' in name:
36
+ name = name.replace('`', '``')
37
+ return f'`{name}`'
38
+
39
+
40
+ # charsets
41
+ utf8mb4 = 'utf8mb4'
42
+ utf8 = 'utf8'
43
+ binary = 'binary'
44
+
45
+ # collations
46
+ utf8_general_ci = 'utf8_general_ci'
47
+ utf8_bin = 'utf8_bin'
48
+ utf8_unicode_ci = 'utf8_unicode_ci'
49
+ utf8_icelandic_ci = 'utf8_icelandic_ci'
50
+ utf8_latvian_ci = 'utf8_latvian_ci'
51
+ utf8_romanian_ci = 'utf8_romanian_ci'
52
+ utf8_slovenian_ci = 'utf8_slovenian_ci'
53
+ utf8_polish_ci = 'utf8_polish_ci'
54
+ utf8_estonian_ci = 'utf8_estonian_ci'
55
+ utf8_spanish_ci = 'utf8_spanish_ci'
56
+ utf8_swedish_ci = 'utf8_swedish_ci'
57
+ utf8_turkish_ci = 'utf8_turkish_ci'
58
+ utf8_czech_ci = 'utf8_czech_ci'
59
+ utf8_danish_ci = 'utf8_danish_ci'
60
+ utf8_lithuanian_ci = 'utf8_lithuanian_ci'
61
+ utf8_slovak_ci = 'utf8_slovak_ci'
62
+ utf8_spanish2_ci = 'utf8_spanish2_ci'
63
+ utf8_roman_ci = 'utf8_roman_ci'
64
+ utf8_persian_ci = 'utf8_persian_ci'
65
+ utf8_esperanto_ci = 'utf8_esperanto_ci'
66
+ utf8_hungarian_ci = 'utf8_hungarian_ci'
67
+ utf8_sinhala_ci = 'utf8_sinhala_ci'
68
+ utf8mb4_general_ci = 'utf8mb4_general_ci'
69
+ utf8mb4_bin = 'utf8mb4_bin'
70
+ utf8mb4_unicode_ci = 'utf8mb4_unicode_ci'
71
+ utf8mb4_icelandic_ci = 'utf8mb4_icelandic_ci'
72
+ utf8mb4_latvian_ci = 'utf8mb4_latvian_ci'
73
+ utf8mb4_romanian_ci = 'utf8mb4_romanian_ci'
74
+ utf8mb4_slovenian_ci = 'utf8mb4_slovenian_ci'
75
+ utf8mb4_polish_ci = 'utf8mb4_polish_ci'
76
+ utf8mb4_estonian_ci = 'utf8mb4_estonian_ci'
77
+ utf8mb4_spanish_ci = 'utf8mb4_spanish_ci'
78
+ utf8mb4_swedish_ci = 'utf8mb4_swedish_ci'
79
+ utf8mb4_turkish_ci = 'utf8mb4_turkish_ci'
80
+ utf8mb4_czech_ci = 'utf8mb4_czech_ci'
81
+ utf8mb4_danish_ci = 'utf8mb4_danish_ci'
82
+ utf8mb4_lithuanian_ci = 'utf8mb4_lithuanian_ci'
83
+ utf8mb4_slovak_ci = 'utf8mb4_slovak_ci'
84
+ utf8mb4_spanish2_ci = 'utf8mb4_spanish2_ci'
85
+ utf8mb4_roman_ci = 'utf8mb4_roman_ci'
86
+ utf8mb4_persian_ci = 'utf8mb4_persian_ci'
87
+ utf8mb4_esperanto_ci = 'utf8mb4_esperanto_ci'
88
+ utf8mb4_hungarian_ci = 'utf8mb4_hungarian_ci'
89
+ utf8mb4_sinhala_ci = 'utf8mb4_sinhala_ci'
90
+
91
+
92
+ def identity(x: Any) -> Any:
93
+ return x
94
+
95
+
96
+ def utf8str(x: Any) -> Optional[str]:
97
+ if x is None:
98
+ return x
99
+ if isinstance(x, str):
100
+ return x
101
+ return str(x, 'utf-8')
102
+
103
+
104
+ def bytestr(x: Any) -> Optional[bytes]:
105
+ if x is None:
106
+ return x
107
+ if isinstance(x, bytes):
108
+ return x
109
+ return base64.b64decode(x)
110
+
111
+
112
+ PYTHON_CONVERTERS = {
113
+ -1: converters[1],
114
+ -2: converters[2],
115
+ -3: converters[3],
116
+ -8: converters[8],
117
+ -9: converters[9],
118
+ 15: utf8str,
119
+ -15: bytestr,
120
+ 249: utf8str,
121
+ -249: bytestr,
122
+ 250: utf8str,
123
+ -250: bytestr,
124
+ 251: utf8str,
125
+ -251: bytestr,
126
+ 252: utf8str,
127
+ -252: bytestr,
128
+ 254: utf8str,
129
+ -254: bytestr,
130
+ 255: utf8str,
131
+ }
132
+
133
+ PYTHON_CONVERTERS = dict(list(converters.items()) + list(PYTHON_CONVERTERS.items()))
134
+
135
+
136
+ def _modifiers(
137
+ *,
138
+ nullable: Optional[bool] = None,
139
+ charset: Optional[str] = None,
140
+ collate: Optional[str] = None,
141
+ default: Optional[Any] = None,
142
+ unsigned: Optional[bool] = None,
143
+ ) -> str:
144
+ """
145
+ Format type modifiers.
146
+
147
+ Parameters
148
+ ----------
149
+ nullable : bool, optional
150
+ Can the value be NULL?
151
+ charset : str, optional
152
+ Character set
153
+ collate : str, optional
154
+ Collation
155
+ default ; Any, optional
156
+ Default value
157
+ unsigned : bool, optional
158
+ Is the value unsigned? (ints only)
159
+
160
+ Returns
161
+ -------
162
+ str
163
+
164
+ """
165
+ out = []
166
+
167
+ if unsigned is not None:
168
+ if unsigned:
169
+ out.append('UNSIGNED')
170
+
171
+ if charset is not None:
172
+ if not re.match(r'^[A-Za-z0-9_]+$', charset):
173
+ raise ValueError(f'charset value is invalid: {charset}')
174
+ out.append(f'CHARACTER SET {charset}')
175
+
176
+ if collate is not None:
177
+ if not re.match(r'^[A-Za-z0-9_]+$', collate):
178
+ raise ValueError(f'collate value is invalid: {collate}')
179
+ out.append(f'COLLATE {collate}')
180
+
181
+ if nullable is not None:
182
+ if nullable:
183
+ out.append('NULL')
184
+ else:
185
+ out.append('NOT NULL')
186
+
187
+ if default is NULL:
188
+ out.append('DEFAULT NULL')
189
+ elif default is not None:
190
+ out.append(f'DEFAULT {escape_item(default, "utf-8")}')
191
+
192
+ return ' ' + ' '.join(out)
193
+
194
+
195
+ def _bool(x: Optional[bool] = None) -> Optional[bool]:
196
+ """Cast bool."""
197
+ if x is None:
198
+ return None
199
+ return bool(x)
200
+
201
+
202
+ def BOOL(
203
+ *,
204
+ nullable: bool = True,
205
+ default: Optional[bool] = None,
206
+ name: Optional[str] = None,
207
+ ) -> SQLString:
208
+ """
209
+ BOOL type specification.
210
+
211
+ Parameters
212
+ ----------
213
+ nullable : bool, optional
214
+ Can the value be NULL?
215
+ default : bool, optional
216
+ Default value
217
+ name : str, optional
218
+ Name of the column / parameter
219
+
220
+ Returns
221
+ -------
222
+ SQLString
223
+
224
+ """
225
+ out = SQLString('BOOL' + _modifiers(nullable=nullable, default=_bool(default)))
226
+ out.name = name
227
+ return out
228
+
229
+
230
+ def BOOLEAN(
231
+ *,
232
+ nullable: bool = True,
233
+ default: Optional[bool] = None,
234
+ name: Optional[str] = None,
235
+ ) -> SQLString:
236
+ """
237
+ BOOLEAN type specification.
238
+
239
+ Parameters
240
+ ----------
241
+ nullable : bool, optional
242
+ Can the value be NULL?
243
+ default : bool, optional
244
+ Default value
245
+ name : str, optional
246
+ Name of the column / parameter
247
+
248
+ Returns
249
+ -------
250
+ SQLString
251
+
252
+ """
253
+ out = SQLString('BOOLEAN' + _modifiers(nullable=nullable, default=_bool(default)))
254
+ out.name = name
255
+ return out
256
+
257
+
258
+ def BIT(
259
+ *,
260
+ nullable: bool = True,
261
+ default: Optional[int] = None,
262
+ name: Optional[str] = None,
263
+ ) -> SQLString:
264
+ """
265
+ BIT type specification.
266
+
267
+ Parameters
268
+ ----------
269
+ nullable : bool, optional
270
+ Can the value be NULL?
271
+ default : int, optional
272
+ Default value
273
+ name : str, optional
274
+ Name of the column / parameter
275
+
276
+ Returns
277
+ -------
278
+ SQLString
279
+
280
+ """
281
+ out = SQLString('BIT' + _modifiers(nullable=nullable, default=default))
282
+ out.name = name
283
+ return out
284
+
285
+
286
+ def TINYINT(
287
+ display_width: Optional[int] = None,
288
+ *,
289
+ nullable: bool = True,
290
+ default: Optional[int] = None,
291
+ unsigned: bool = False,
292
+ name: Optional[str] = None,
293
+ ) -> SQLString:
294
+ """
295
+ TINYINT type specification.
296
+
297
+ Parameters
298
+ ----------
299
+ display_width : int, optional
300
+ Display width used by some clients
301
+ nullable : bool, optional
302
+ Can the value be NULL?
303
+ default : int, optional
304
+ Default value
305
+ unsigned : bool, optional
306
+ Is the int unsigned?
307
+ name : str, optional
308
+ Name of the column / parameter
309
+
310
+ Returns
311
+ -------
312
+ SQLString
313
+
314
+ """
315
+ out = f'TINYINT({display_width})' if display_width else 'TINYINT'
316
+ out = SQLString(
317
+ out + _modifiers(nullable=nullable, default=default, unsigned=unsigned),
318
+ )
319
+ out.name = name
320
+ return out
321
+
322
+
323
+ def TINYINT_UNSIGNED(
324
+ display_width: Optional[int] = None,
325
+ *,
326
+ nullable: bool = True,
327
+ default: Optional[int] = None,
328
+ name: Optional[str] = None,
329
+ ) -> SQLString:
330
+ """
331
+ TINYINT UNSIGNED type specification.
332
+
333
+ Parameters
334
+ ----------
335
+ display_width : int, optional
336
+ Display width used by some clients
337
+ nullable : bool, optional
338
+ Can the value be NULL?
339
+ default : int, optional
340
+ Default value
341
+ name : str, optional
342
+ Name of the column / parameter
343
+
344
+ Returns
345
+ -------
346
+ SQLString
347
+
348
+ """
349
+ out = f'TINYINT({display_width})' if display_width else 'TINYINT'
350
+ out = SQLString(out + _modifiers(nullable=nullable, default=default, unsigned=True))
351
+ out.name = name
352
+ return out
353
+
354
+
355
+ def SMALLINT(
356
+ display_width: Optional[int] = None,
357
+ *,
358
+ nullable: bool = True,
359
+ default: Optional[int] = None,
360
+ unsigned: bool = False,
361
+ name: Optional[str] = None,
362
+ ) -> SQLString:
363
+ """
364
+ SMALLINT type specification.
365
+
366
+ Parameters
367
+ ----------
368
+ display_width : int, optional
369
+ Display width used by some clients
370
+ nullable : bool, optional
371
+ Can the value be NULL?
372
+ default : int, optional
373
+ Default value
374
+ unsigned : bool, optional
375
+ Is the int unsigned?
376
+ name : str, optional
377
+ Name of the column / parameter
378
+
379
+ Returns
380
+ -------
381
+ SQLString
382
+
383
+ """
384
+ out = f'SMALLINT({display_width})' if display_width else 'SMALLINT'
385
+ out = SQLString(
386
+ out + _modifiers(nullable=nullable, default=default, unsigned=unsigned),
387
+ )
388
+ out.name = name
389
+ return out
390
+
391
+
392
+ def SMALLINT_UNSIGNED(
393
+ display_width: Optional[int] = None,
394
+ *,
395
+ nullable: bool = True,
396
+ default: Optional[int] = None,
397
+ name: Optional[str] = None,
398
+ ) -> SQLString:
399
+ """
400
+ SMALLINT UNSIGNED type specification.
401
+
402
+ Parameters
403
+ ----------
404
+ display_width : int, optional
405
+ Display width used by some clients
406
+ nullable : bool, optional
407
+ Can the value be NULL?
408
+ default : int, optional
409
+ Default value
410
+ name : str, optional
411
+ Name of the column / parameter
412
+
413
+ Returns
414
+ -------
415
+ SQLString
416
+
417
+ """
418
+ out = f'SMALLINT({display_width})' if display_width else 'SMALLINT'
419
+ out = SQLString(out + _modifiers(nullable=nullable, default=default, unsigned=True))
420
+ out.name = name
421
+ return out
422
+
423
+
424
+ def MEDIUMINT(
425
+ display_width: Optional[int] = None,
426
+ *,
427
+ nullable: bool = True,
428
+ default: Optional[int] = None,
429
+ unsigned: bool = False,
430
+ name: Optional[str] = None,
431
+ ) -> SQLString:
432
+ """
433
+ MEDIUMINT type specification.
434
+
435
+ Parameters
436
+ ----------
437
+ display_width : int, optional
438
+ Display width used by some clients
439
+ nullable : bool, optional
440
+ Can the value be NULL?
441
+ default : int, optional
442
+ Default value
443
+ unsigned : bool, optional
444
+ Is the int unsigned?
445
+ name : str, optional
446
+ Name of the column / parameter
447
+
448
+ Returns
449
+ -------
450
+ SQLString
451
+
452
+ """
453
+ out = f'MEDIUMINT({display_width})' if display_width else 'MEDIUMINT'
454
+ out = SQLString(
455
+ out + _modifiers(nullable=nullable, default=default, unsigned=unsigned),
456
+ )
457
+ out.name = name
458
+ return out
459
+
460
+
461
+ def MEDIUMINT_UNSIGNED(
462
+ display_width: Optional[int] = None,
463
+ *,
464
+ nullable: bool = True,
465
+ default: Optional[int] = None,
466
+ name: Optional[str] = None,
467
+ ) -> SQLString:
468
+ """
469
+ MEDIUMINT UNSIGNED type specification.
470
+
471
+ Parameters
472
+ ----------
473
+ display_width : int, optional
474
+ Display width used by some clients
475
+ nullable : bool, optional
476
+ Can the value be NULL?
477
+ default : int, optional
478
+ Default value
479
+ name : str, optional
480
+ Name of the column / parameter
481
+
482
+ Returns
483
+ -------
484
+ SQLString
485
+
486
+ """
487
+ out = f'MEDIUMINT({display_width})' if display_width else 'MEDIUMINT'
488
+ out = SQLString(out + _modifiers(nullable=nullable, default=default, unsigned=True))
489
+ out.name = name
490
+ return out
491
+
492
+
493
+ def INT(
494
+ display_width: Optional[int] = None,
495
+ *,
496
+ nullable: bool = True,
497
+ default: Optional[int] = None,
498
+ unsigned: bool = False,
499
+ name: Optional[str] = None,
500
+ ) -> SQLString:
501
+ """
502
+ INT type specification.
503
+
504
+ Parameters
505
+ ----------
506
+ display_width : int, optional
507
+ Display width used by some clients
508
+ nullable : bool, optional
509
+ Can the value be NULL?
510
+ default : int, optional
511
+ Default value
512
+ unsigned : bool, optional
513
+ Is the int unsigned?
514
+ name : str, optional
515
+ Name of the column / parameter
516
+
517
+ Returns
518
+ -------
519
+ SQLString
520
+
521
+ """
522
+ out = f'INT({display_width})' if display_width else 'INT'
523
+ out = SQLString(
524
+ out + _modifiers(nullable=nullable, default=default, unsigned=unsigned),
525
+ )
526
+ out.name = name
527
+ return out
528
+
529
+
530
+ def INT_UNSIGNED(
531
+ display_width: Optional[int] = None,
532
+ *,
533
+ nullable: bool = True,
534
+ default: Optional[int] = None,
535
+ name: Optional[str] = None,
536
+ ) -> SQLString:
537
+ """
538
+ INT UNSIGNED type specification.
539
+
540
+ Parameters
541
+ ----------
542
+ display_width : int, optional
543
+ Display width used by some clients
544
+ nullable : bool, optional
545
+ Can the value be NULL?
546
+ default : int, optional
547
+ Default value
548
+ name : str, optional
549
+ Name of the column / parameter
550
+
551
+ Returns
552
+ -------
553
+ SQLString
554
+
555
+ """
556
+ out = f'INT({display_width})' if display_width else 'INT'
557
+ out = SQLString(out + _modifiers(nullable=nullable, default=default, unsigned=True))
558
+ out.name = name
559
+ return out
560
+
561
+
562
+ def INTEGER(
563
+ display_width: Optional[int] = None,
564
+ *,
565
+ nullable: bool = True,
566
+ default: Optional[int] = None,
567
+ unsigned: bool = False,
568
+ name: Optional[str] = None,
569
+ ) -> SQLString:
570
+ """
571
+ INTEGER type specification.
572
+
573
+ Parameters
574
+ ----------
575
+ display_width : int, optional
576
+ Display width used by some clients
577
+ nullable : bool, optional
578
+ Can the value be NULL?
579
+ default : int, optional
580
+ Default value
581
+ unsigned : bool, optional
582
+ Is the int unsigned?
583
+ name : str, optional
584
+ Name of the column / parameter
585
+
586
+ Returns
587
+ -------
588
+ SQLString
589
+
590
+ """
591
+ out = f'INTEGER({display_width})' if display_width else 'INTEGER'
592
+ out = SQLString(
593
+ out + _modifiers(nullable=nullable, default=default, unsigned=unsigned),
594
+ )
595
+ out.name = name
596
+ return out
597
+
598
+
599
+ def INTEGER_UNSIGNED(
600
+ display_width: Optional[int] = None,
601
+ *,
602
+ nullable: bool = True,
603
+ default: Optional[int] = None,
604
+ name: Optional[str] = None,
605
+ ) -> SQLString:
606
+ """
607
+ INTEGER UNSIGNED type specification.
608
+
609
+ Parameters
610
+ ----------
611
+ display_width : int, optional
612
+ Display width used by some clients
613
+ nullable : bool, optional
614
+ Can the value be NULL?
615
+ default : int, optional
616
+ Default value
617
+ name : str, optional
618
+ Name of the column / parameter
619
+
620
+ Returns
621
+ -------
622
+ SQLString
623
+
624
+ """
625
+ out = f'INTEGER({display_width})' if display_width else 'INTEGER'
626
+ out = SQLString(out + _modifiers(nullable=nullable, default=default, unsigned=True))
627
+ out.name = name
628
+ return out
629
+
630
+
631
+ def BIGINT(
632
+ display_width: Optional[int] = None,
633
+ *,
634
+ nullable: bool = True,
635
+ default: Optional[int] = None,
636
+ unsigned: bool = False,
637
+ name: Optional[str] = None,
638
+ ) -> SQLString:
639
+ """
640
+ BIGINT type specification.
641
+
642
+ Parameters
643
+ ----------
644
+ display_width : int, optional
645
+ Display width used by some clients
646
+ nullable : bool, optional
647
+ Can the value be NULL?
648
+ default : int, optional
649
+ Default value
650
+ unsigned : bool, optional
651
+ Is the int unsigned?
652
+ name : str, optional
653
+ Name of the column / parameter
654
+
655
+ Returns
656
+ -------
657
+ SQLString
658
+
659
+ """
660
+ out = f'BIGINT({display_width})' if display_width else 'BIGINT'
661
+ out = SQLString(
662
+ out + _modifiers(nullable=nullable, default=default, unsigned=unsigned),
663
+ )
664
+ out.name = name
665
+ return out
666
+
667
+
668
+ def BIGINT_UNSIGNED(
669
+ display_width: Optional[int] = None,
670
+ *,
671
+ nullable: bool = True,
672
+ default: Optional[int] = None,
673
+ name: Optional[str] = None,
674
+ ) -> SQLString:
675
+ """
676
+ BIGINT UNSIGNED type specification.
677
+
678
+ Parameters
679
+ ----------
680
+ display_width : int, optional
681
+ Display width used by some clients
682
+ nullable : bool, optional
683
+ Can the value be NULL?
684
+ default : int, optional
685
+ Default value
686
+ name : str, optional
687
+ Name of the column / parameter
688
+
689
+ Returns
690
+ -------
691
+ SQLString
692
+
693
+ """
694
+ out = f'BIGINT({int(display_width)})' if display_width else 'BIGINT'
695
+ out = SQLString(out + _modifiers(nullable=nullable, default=default, unsigned=True))
696
+ out.name = name
697
+ return out
698
+
699
+
700
+ def FLOAT(
701
+ display_decimals: Optional[int] = None,
702
+ *,
703
+ nullable: bool = True,
704
+ default: Optional[float] = None,
705
+ name: Optional[str] = None,
706
+ ) -> SQLString:
707
+ """
708
+ FLOAT type specification.
709
+
710
+ Parameters
711
+ ----------
712
+ display_decimals : int, optional
713
+ Number of decimal places to display
714
+ nullable : bool, optional
715
+ Can the value be NULL?
716
+ default : float, optional
717
+ Default value
718
+ name : str, optional
719
+ Name of the column / parameter
720
+
721
+ Returns
722
+ -------
723
+ SQLString
724
+
725
+ """
726
+ out = f'FLOAT({int(display_decimals)})' if display_decimals else 'FLOAT'
727
+ out = SQLString(out + _modifiers(nullable=nullable, default=default))
728
+ out.name = name
729
+ return out
730
+
731
+
732
+ def DOUBLE(
733
+ display_decimals: Optional[int] = None,
734
+ *,
735
+ nullable: bool = True,
736
+ default: Optional[float] = None,
737
+ name: Optional[str] = None,
738
+ ) -> SQLString:
739
+ """
740
+ DOUBLE type specification.
741
+
742
+ Parameters
743
+ ----------
744
+ display_decimals : int, optional
745
+ Number of decimal places to display
746
+ nullable : bool, optional
747
+ Can the value be NULL?
748
+ default : float, optional
749
+ Default value
750
+ name : str, optional
751
+ Name of the column / parameter
752
+
753
+ Returns
754
+ -------
755
+ SQLString
756
+
757
+ """
758
+ out = f'DOUBLE({int(display_decimals)})' if display_decimals else 'DOUBLE'
759
+ out = SQLString(out + _modifiers(nullable=nullable, default=default))
760
+ out.name = name
761
+ return out
762
+
763
+
764
+ def REAL(
765
+ display_decimals: Optional[int] = None,
766
+ *,
767
+ nullable: bool = True,
768
+ default: Optional[float] = None,
769
+ name: Optional[str] = None,
770
+ ) -> SQLString:
771
+ """
772
+ REAL type specification.
773
+
774
+ Parameters
775
+ ----------
776
+ display_decimals : int, optional
777
+ Number of decimal places to display
778
+ nullable : bool, optional
779
+ Can the value be NULL?
780
+ default : float, optional
781
+ Default value
782
+ name : str, optional
783
+ Name of the column / parameter
784
+
785
+ Returns
786
+ -------
787
+ SQLString
788
+
789
+ """
790
+ out = f'REAL({int(display_decimals)})' if display_decimals else 'REAL'
791
+ out = SQLString(out + _modifiers(nullable=nullable, default=default))
792
+ out.name = name
793
+ return out
794
+
795
+
796
+ def DECIMAL(
797
+ precision: int,
798
+ scale: int,
799
+ *,
800
+ nullable: bool = True,
801
+ default: Optional[Union[str, decimal.Decimal]] = None,
802
+ name: Optional[str] = None,
803
+ ) -> SQLString:
804
+ """
805
+ DECIMAL type specification.
806
+
807
+ Parameters
808
+ ----------
809
+ precision : int
810
+ Decimal precision
811
+ scale : int
812
+ Decimal scale
813
+ nullable : bool, optional
814
+ Can the value be NULL?
815
+ default : str or decimal.Decimal, optional
816
+ Default value
817
+ name : str, optional
818
+ Name of the column / parameter
819
+
820
+ Returns
821
+ -------
822
+ SQLString
823
+
824
+ """
825
+ out = SQLString(
826
+ f'DECIMAL({int(precision)}, {int(scale)})' +
827
+ _modifiers(nullable=nullable, default=default),
828
+ )
829
+ out.name = name
830
+ return out
831
+
832
+
833
+ def DEC(
834
+ precision: int,
835
+ scale: int,
836
+ *,
837
+ nullable: bool = True,
838
+ default: Optional[Union[str, decimal.Decimal]] = None,
839
+ name: Optional[str] = None,
840
+ ) -> SQLString:
841
+ """
842
+ DEC type specification.
843
+
844
+ Parameters
845
+ ----------
846
+ precision : int
847
+ Decimal precision
848
+ scale : int
849
+ Decimal scale
850
+ nullable : bool, optional
851
+ Can the value be NULL?
852
+ default : str or decimal.Decimal, optional
853
+ Default value
854
+ name : str, optional
855
+ Name of the column / parameter
856
+
857
+ Returns
858
+ -------
859
+ SQLString
860
+
861
+ """
862
+ out = SQLString(
863
+ f'DEC({int(precision)}, {int(scale)})' +
864
+ _modifiers(nullable=nullable, default=default),
865
+ )
866
+ out.name = name
867
+ return out
868
+
869
+
870
+ def FIXED(
871
+ precision: int,
872
+ scale: int,
873
+ *,
874
+ nullable: bool = True,
875
+ default: Optional[Union[str, decimal.Decimal]] = None,
876
+ name: Optional[str] = None,
877
+ ) -> SQLString:
878
+ """
879
+ FIXED type specification.
880
+
881
+ Parameters
882
+ ----------
883
+ precision : int
884
+ Decimal precision
885
+ scale : int
886
+ Decimal scale
887
+ nullable : bool, optional
888
+ Can the value be NULL?
889
+ default : str or decimal.Decimal, optional
890
+ Default value
891
+ name : str, optional
892
+ Name of the column / parameter
893
+
894
+ Returns
895
+ -------
896
+ SQLString
897
+
898
+ """
899
+ out = SQLString(
900
+ f'FIXED({int(precision)}, {int(scale)})' +
901
+ _modifiers(nullable=nullable, default=default),
902
+ )
903
+ out.name = name
904
+ return out
905
+
906
+
907
+ def NUMERIC(
908
+ precision: int,
909
+ scale: int,
910
+ *,
911
+ nullable: bool = True,
912
+ default: Optional[Union[str, decimal.Decimal]] = None,
913
+ name: Optional[str] = None,
914
+ ) -> SQLString:
915
+ """
916
+ NUMERIC type specification.
917
+
918
+ Parameters
919
+ ----------
920
+ precision : int
921
+ Decimal precision
922
+ scale : int
923
+ Decimal scale
924
+ nullable : bool, optional
925
+ Can the value be NULL?
926
+ default : str or decimal.Decimal, optional
927
+ Default value
928
+ name : str, optional
929
+ Name of the column / parameter
930
+
931
+ Returns
932
+ -------
933
+ SQLString
934
+
935
+ """
936
+ out = SQLString(
937
+ f'NUMERIC({int(precision)}, {int(scale)})' +
938
+ _modifiers(nullable=nullable, default=default),
939
+ )
940
+ out.name = name
941
+ return out
942
+
943
+
944
+ def DATE(
945
+ *,
946
+ nullable: bool = True,
947
+ default: Optional[Union[str, datetime.date]] = None,
948
+ name: Optional[str] = None,
949
+ ) -> SQLString:
950
+ """
951
+ DATE type specification.
952
+
953
+ Parameters
954
+ ----------
955
+ nullable : bool, optional
956
+ Can the value be NULL?
957
+ default : str or datetime.date, optional
958
+ Default value
959
+ name : str, optional
960
+ Name of the column / parameter
961
+
962
+ Returns
963
+ -------
964
+ SQLString
965
+
966
+ """
967
+ out = SQLString('DATE' + _modifiers(nullable=nullable, default=default))
968
+ out.name = name
969
+ return out
970
+
971
+
972
+ def TIME(
973
+ precision: Optional[int] = None,
974
+ *,
975
+ nullable: bool = True,
976
+ default: Optional[Union[str, datetime.timedelta]] = None,
977
+ name: Optional[str] = None,
978
+ ) -> SQLString:
979
+ """
980
+ TIME type specification.
981
+
982
+ Parameters
983
+ ----------
984
+ precision : int, optional
985
+ Sub-second precision
986
+ nullable : bool, optional
987
+ Can the value be NULL?
988
+ default : str or datetime.timedelta, optional
989
+ Default value
990
+ name : str, optional
991
+ Name of the column / parameter
992
+
993
+ Returns
994
+ -------
995
+ SQLString
996
+
997
+ """
998
+ out = f'TIME({int(precision)})' if precision else 'TIME'
999
+ out = SQLString(out + _modifiers(nullable=nullable, default=default))
1000
+ out.name = name
1001
+ return out
1002
+
1003
+
1004
+ def DATETIME(
1005
+ precision: Optional[int] = None,
1006
+ *,
1007
+ nullable: bool = True,
1008
+ default: Optional[Union[str, datetime.datetime]] = None,
1009
+ name: Optional[str] = None,
1010
+ ) -> SQLString:
1011
+ """
1012
+ DATETIME type specification.
1013
+
1014
+ Parameters
1015
+ ----------
1016
+ precision : int, optional
1017
+ Sub-second precision
1018
+ nullable : bool, optional
1019
+ Can the value be NULL?
1020
+ default : str or datetime.datetime, optional
1021
+ Default value
1022
+ name : str, optional
1023
+ Name of the column / parameter
1024
+
1025
+ Returns
1026
+ -------
1027
+ SQLString
1028
+
1029
+ """
1030
+ out = f'DATETIME({int(precision)})' if precision else 'DATETIME'
1031
+ out = SQLString(out + _modifiers(nullable=nullable, default=default))
1032
+ out.name = name
1033
+ return out
1034
+
1035
+
1036
+ def TIMESTAMP(
1037
+ precision: Optional[int] = None,
1038
+ *,
1039
+ nullable: bool = True,
1040
+ default: Optional[Union[str, datetime.datetime]] = None,
1041
+ name: Optional[str] = None,
1042
+ ) -> SQLString:
1043
+ """
1044
+ TIMESTAMP type specification.
1045
+
1046
+ Parameters
1047
+ ----------
1048
+ precision : int, optional
1049
+ Sub-second precision
1050
+ nullable : bool, optional
1051
+ Can the value be NULL?
1052
+ default : str or datetime.datetime, optional
1053
+ Default value
1054
+ name : str, optional
1055
+ Name of the column / parameter
1056
+
1057
+ Returns
1058
+ -------
1059
+ SQLString
1060
+
1061
+ """
1062
+ out = f'TIMESTAMP({int(precision)})' if precision else 'TIMESTAMP'
1063
+ out = SQLString(out + _modifiers(nullable=nullable, default=default))
1064
+ out.name = name
1065
+ return out
1066
+
1067
+
1068
+ def YEAR(
1069
+ *,
1070
+ nullable: bool = True,
1071
+ default: Optional[int] = None,
1072
+ name: Optional[str] = None,
1073
+ ) -> SQLString:
1074
+ """
1075
+ YEAR type specification.
1076
+
1077
+ Parameters
1078
+ ----------
1079
+ nullable : bool, optional
1080
+ Can the value be NULL?
1081
+ default : int, optional
1082
+ Default value
1083
+ name : str, optional
1084
+ Name of the column / parameter
1085
+
1086
+ Returns
1087
+ -------
1088
+ SQLString
1089
+
1090
+ """
1091
+ out = SQLString('YEAR' + _modifiers(nullable=nullable, default=default))
1092
+ out.name = name
1093
+ return out
1094
+
1095
+
1096
+ def CHAR(
1097
+ length: Optional[int] = None,
1098
+ *,
1099
+ nullable: bool = True,
1100
+ default: Optional[str] = None,
1101
+ collate: Optional[str] = None,
1102
+ charset: Optional[str] = None,
1103
+ name: Optional[str] = None,
1104
+ ) -> SQLString:
1105
+ """
1106
+ CHAR type specification.
1107
+
1108
+ Parameters
1109
+ ----------
1110
+ length : int, optional
1111
+ Maximum string length
1112
+ nullable : bool, optional
1113
+ Can the value be NULL?
1114
+ default : str, optional
1115
+ Default value
1116
+ collate : str, optional
1117
+ Collation
1118
+ charset : str, optional
1119
+ Character set
1120
+ name : str, optional
1121
+ Name of the column / parameter
1122
+
1123
+ Returns
1124
+ -------
1125
+ SQLString
1126
+
1127
+ """
1128
+ out = f'CHAR({int(length)})' if length else 'CHAR'
1129
+ out = SQLString(
1130
+ out + _modifiers(
1131
+ nullable=nullable, default=default,
1132
+ collate=collate, charset=charset,
1133
+ ),
1134
+ )
1135
+ out.name = name
1136
+ return out
1137
+
1138
+
1139
+ def VARCHAR(
1140
+ length: Optional[int] = None,
1141
+ *,
1142
+ nullable: bool = True,
1143
+ default: Optional[str] = None,
1144
+ collate: Optional[str] = None,
1145
+ charset: Optional[str] = None,
1146
+ name: Optional[str] = None,
1147
+ ) -> SQLString:
1148
+ """
1149
+ VARCHAR type specification.
1150
+
1151
+ Parameters
1152
+ ----------
1153
+ length : int, optional
1154
+ Maximum string length
1155
+ nullable : bool, optional
1156
+ Can the value be NULL?
1157
+ default : str, optional
1158
+ Default value
1159
+ collate : str, optional
1160
+ Collation
1161
+ charset : str, optional
1162
+ Character set
1163
+ name : str, optional
1164
+ Name of the column / parameter
1165
+
1166
+ Returns
1167
+ -------
1168
+ SQLString
1169
+
1170
+ """
1171
+ out = f'VARCHAR({int(length)})' if length else 'VARCHAR'
1172
+ out = SQLString(
1173
+ out + _modifiers(
1174
+ nullable=nullable, default=default,
1175
+ collate=collate, charset=charset,
1176
+ ),
1177
+ )
1178
+ out.name = name
1179
+ return out
1180
+
1181
+
1182
+ def LONGTEXT(
1183
+ length: Optional[int] = None,
1184
+ *,
1185
+ nullable: bool = True,
1186
+ default: Optional[str] = None,
1187
+ collate: Optional[str] = None,
1188
+ charset: Optional[str] = None,
1189
+ name: Optional[str] = None,
1190
+ ) -> SQLString:
1191
+ """
1192
+ LONGTEXT type specification.
1193
+
1194
+ Parameters
1195
+ ----------
1196
+ length : int, optional
1197
+ Maximum string length
1198
+ nullable : bool, optional
1199
+ Can the value be NULL?
1200
+ default : str, optional
1201
+ Default value
1202
+ collate : str, optional
1203
+ Collation
1204
+ charset : str, optional
1205
+ Character set
1206
+ name : str, optional
1207
+ Name of the column / parameter
1208
+
1209
+ Returns
1210
+ -------
1211
+ SQLString
1212
+
1213
+ """
1214
+ out = f'LONGTEXT({int(length)})' if length else 'LONGTEXT'
1215
+ out = SQLString(
1216
+ out + _modifiers(
1217
+ nullable=nullable, default=default,
1218
+ collate=collate, charset=charset,
1219
+ ),
1220
+ )
1221
+ out.name = name
1222
+ return out
1223
+
1224
+
1225
+ def MEDIUMTEXT(
1226
+ length: Optional[int] = None,
1227
+ *,
1228
+ nullable: bool = True,
1229
+ default: Optional[str] = None,
1230
+ collate: Optional[str] = None,
1231
+ charset: Optional[str] = None,
1232
+ name: Optional[str] = None,
1233
+ ) -> SQLString:
1234
+ """
1235
+ MEDIUMTEXT type specification.
1236
+
1237
+ Parameters
1238
+ ----------
1239
+ length : int, optional
1240
+ Maximum string length
1241
+ nullable : bool, optional
1242
+ Can the value be NULL?
1243
+ default : str, optional
1244
+ Default value
1245
+ collate : str, optional
1246
+ Collation
1247
+ charset : str, optional
1248
+ Character set
1249
+ name : str, optional
1250
+ Name of the column / parameter
1251
+
1252
+ Returns
1253
+ -------
1254
+ SQLString
1255
+
1256
+ """
1257
+ out = f'MEDIUMTEXT({int(length)})' if length else 'MEDIUMTEXT'
1258
+ out = SQLString(
1259
+ out + _modifiers(
1260
+ nullable=nullable, default=default,
1261
+ collate=collate, charset=charset,
1262
+ ),
1263
+ )
1264
+ out.name = name
1265
+ return out
1266
+
1267
+
1268
+ def TEXT(
1269
+ length: Optional[int] = None,
1270
+ *,
1271
+ nullable: bool = True,
1272
+ default: Optional[str] = None,
1273
+ collate: Optional[str] = None,
1274
+ charset: Optional[str] = None,
1275
+ name: Optional[str] = None,
1276
+ ) -> SQLString:
1277
+ """
1278
+ TEXT type specification.
1279
+
1280
+ Parameters
1281
+ ----------
1282
+ length : int, optional
1283
+ Maximum string length
1284
+ nullable : bool, optional
1285
+ Can the value be NULL?
1286
+ default : str, optional
1287
+ Default value
1288
+ collate : str, optional
1289
+ Collation
1290
+ charset : str, optional
1291
+ Character set
1292
+ name : str, optional
1293
+ Name of the column / parameter
1294
+
1295
+ Returns
1296
+ -------
1297
+ SQLString
1298
+
1299
+ """
1300
+ out = f'TEXT({int(length)})' if length else 'TEXT'
1301
+ out = SQLString(
1302
+ out + _modifiers(
1303
+ nullable=nullable, default=default,
1304
+ collate=collate, charset=charset,
1305
+ ),
1306
+ )
1307
+ out.name = name
1308
+ return out
1309
+
1310
+
1311
+ def TINYTEXT(
1312
+ length: Optional[int] = None,
1313
+ *,
1314
+ nullable: bool = True,
1315
+ default: Optional[str] = None,
1316
+ collate: Optional[str] = None,
1317
+ charset: Optional[str] = None,
1318
+ name: Optional[str] = None,
1319
+ ) -> SQLString:
1320
+ """
1321
+ TINYTEXT type specification.
1322
+
1323
+ Parameters
1324
+ ----------
1325
+ length : int, optional
1326
+ Maximum string length
1327
+ nullable : bool, optional
1328
+ Can the value be NULL?
1329
+ default : str, optional
1330
+ Default value
1331
+ collate : str, optional
1332
+ Collation
1333
+ charset : str, optional
1334
+ Character set
1335
+ name : str, optional
1336
+ Name of the column / parameter
1337
+
1338
+ Returns
1339
+ -------
1340
+ SQLString
1341
+
1342
+ """
1343
+ out = f'TINYTEXT({int(length)})' if length else 'TINYTEXT'
1344
+ out = SQLString(
1345
+ out + _modifiers(
1346
+ nullable=nullable, default=default,
1347
+ collate=collate, charset=charset,
1348
+ ),
1349
+ )
1350
+ out.name = name
1351
+ return out
1352
+
1353
+
1354
+ def BINARY(
1355
+ length: Optional[int] = None,
1356
+ *,
1357
+ nullable: bool = True,
1358
+ default: Optional[bytes] = None,
1359
+ collate: Optional[str] = None,
1360
+ name: Optional[str] = None,
1361
+ ) -> SQLString:
1362
+ """
1363
+ BINARY type specification.
1364
+
1365
+ Parameters
1366
+ ----------
1367
+ length : int, optional
1368
+ Maximum string length
1369
+ nullable : bool, optional
1370
+ Can the value be NULL?
1371
+ default : str, optional
1372
+ Default value
1373
+ collate : str, optional
1374
+ Collation
1375
+ name : str, optional
1376
+ Name of the column / parameter
1377
+
1378
+ Returns
1379
+ -------
1380
+ SQLString
1381
+
1382
+ """
1383
+ out = f'BINARY({int(length)})' if length else 'BINARY'
1384
+ out = SQLString(
1385
+ out + _modifiers(
1386
+ nullable=nullable, default=default, collate=collate,
1387
+ ),
1388
+ )
1389
+ out.name = name
1390
+ return out
1391
+
1392
+
1393
+ def VARBINARY(
1394
+ length: Optional[int] = None,
1395
+ *,
1396
+ nullable: bool = True,
1397
+ default: Optional[bytes] = None,
1398
+ collate: Optional[str] = None,
1399
+ name: Optional[str] = None,
1400
+ ) -> SQLString:
1401
+ """
1402
+ VARBINARY type specification.
1403
+
1404
+ Parameters
1405
+ ----------
1406
+ length : int, optional
1407
+ Maximum string length
1408
+ nullable : bool, optional
1409
+ Can the value be NULL?
1410
+ default : str, optional
1411
+ Default value
1412
+ collate : str, optional
1413
+ Collation
1414
+ name : str, optional
1415
+ Name of the column / parameter
1416
+
1417
+ Returns
1418
+ -------
1419
+ SQLString
1420
+
1421
+ """
1422
+ out = f'VARBINARY({int(length)})' if length else 'VARBINARY'
1423
+ out = SQLString(
1424
+ out + _modifiers(
1425
+ nullable=nullable, default=default, collate=collate,
1426
+ ),
1427
+ )
1428
+ out.name = name
1429
+ return out
1430
+
1431
+
1432
+ def LONGBLOB(
1433
+ length: Optional[int] = None,
1434
+ *,
1435
+ nullable: bool = True,
1436
+ default: Optional[bytes] = None,
1437
+ collate: Optional[str] = None,
1438
+ name: Optional[str] = None,
1439
+ ) -> SQLString:
1440
+ """
1441
+ LONGBLOB type specification.
1442
+
1443
+ Parameters
1444
+ ----------
1445
+ length : int, optional
1446
+ Maximum string length
1447
+ nullable : bool, optional
1448
+ Can the value be NULL?
1449
+ default : str, optional
1450
+ Default value
1451
+ collate : str, optional
1452
+ Collation
1453
+ name : str, optional
1454
+ Name of the column / parameter
1455
+
1456
+ Returns
1457
+ -------
1458
+ SQLString
1459
+
1460
+ """
1461
+ out = f'LONGBLOB({int(length)})' if length else 'LONGBLOB'
1462
+ out = SQLString(
1463
+ out + _modifiers(
1464
+ nullable=nullable, default=default, collate=collate,
1465
+ ),
1466
+ )
1467
+ out.name = name
1468
+ return out
1469
+
1470
+
1471
+ def MEDIUMBLOB(
1472
+ length: Optional[int] = None,
1473
+ *,
1474
+ nullable: bool = True,
1475
+ default: Optional[bytes] = None,
1476
+ collate: Optional[str] = None,
1477
+ name: Optional[str] = None,
1478
+ ) -> SQLString:
1479
+ """
1480
+ MEDIUMBLOB type specification.
1481
+
1482
+ Parameters
1483
+ ----------
1484
+ length : int, optional
1485
+ Maximum string length
1486
+ nullable : bool, optional
1487
+ Can the value be NULL?
1488
+ default : str, optional
1489
+ Default value
1490
+ collate : str, optional
1491
+ Collation
1492
+ name : str, optional
1493
+ Name of the column / parameter
1494
+
1495
+ Returns
1496
+ -------
1497
+ SQLString
1498
+
1499
+ """
1500
+ out = f'MEDIUMBLOB({int(length)})' if length else 'MEDIUMBLOB'
1501
+ out = SQLString(
1502
+ out + _modifiers(
1503
+ nullable=nullable, default=default, collate=collate,
1504
+ ),
1505
+ )
1506
+ out.name = name
1507
+ return out
1508
+
1509
+
1510
+ def BLOB(
1511
+ length: Optional[int] = None,
1512
+ *,
1513
+ nullable: bool = True,
1514
+ default: Optional[bytes] = None,
1515
+ collate: Optional[str] = None,
1516
+ name: Optional[str] = None,
1517
+ ) -> SQLString:
1518
+ """
1519
+ BLOB type specification.
1520
+
1521
+ Parameters
1522
+ ----------
1523
+ length : int, optional
1524
+ Maximum string length
1525
+ nullable : bool, optional
1526
+ Can the value be NULL?
1527
+ default : str, optional
1528
+ Default value
1529
+ collate : str, optional
1530
+ Collation
1531
+ name : str, optional
1532
+ Name of the column / parameter
1533
+
1534
+ Returns
1535
+ -------
1536
+ SQLString
1537
+
1538
+ """
1539
+ out = f'BLOB({int(length)})' if length else 'BLOB'
1540
+ out = SQLString(
1541
+ out + _modifiers(
1542
+ nullable=nullable, default=default, collate=collate,
1543
+ ),
1544
+ )
1545
+ out.name = name
1546
+ return out
1547
+
1548
+
1549
+ def TINYBLOB(
1550
+ length: Optional[int] = None,
1551
+ *,
1552
+ nullable: bool = True,
1553
+ default: Optional[bytes] = None,
1554
+ collate: Optional[str] = None,
1555
+ name: Optional[str] = None,
1556
+ ) -> SQLString:
1557
+ """
1558
+ TINYBLOB type specification.
1559
+
1560
+ Parameters
1561
+ ----------
1562
+ length : int, optional
1563
+ Maximum string length
1564
+ nullable : bool, optional
1565
+ Can the value be NULL?
1566
+ default : str, optional
1567
+ Default value
1568
+ collate : str, optional
1569
+ Collation
1570
+ name : str, optional
1571
+ Name of the column / parameter
1572
+
1573
+ Returns
1574
+ -------
1575
+ SQLString
1576
+
1577
+ """
1578
+ out = f'TINYBLOB({int(length)})' if length else 'TINYBLOB'
1579
+ out = SQLString(
1580
+ out + _modifiers(
1581
+ nullable=nullable, default=default, collate=collate,
1582
+ ),
1583
+ )
1584
+ out.name = name
1585
+ return out
1586
+
1587
+
1588
+ def JSON(
1589
+ length: Optional[int] = None,
1590
+ *,
1591
+ nullable: bool = True,
1592
+ default: Optional[str] = None,
1593
+ collate: Optional[str] = None,
1594
+ charset: Optional[str] = None,
1595
+ name: Optional[str] = None,
1596
+ ) -> SQLString:
1597
+ """
1598
+ JSON type specification.
1599
+
1600
+ Parameters
1601
+ ----------
1602
+ length : int, optional
1603
+ Maximum string length
1604
+ nullable : bool, optional
1605
+ Can the value be NULL?
1606
+ default : str, optional
1607
+ Default value
1608
+ collate : str, optional
1609
+ Collation
1610
+ charset : str, optional
1611
+ Character set
1612
+ name : str, optional
1613
+ Name of the column / parameter
1614
+
1615
+ Returns
1616
+ -------
1617
+ SQLString
1618
+
1619
+ """
1620
+ out = f'JSON({int(length)})' if length else 'JSON'
1621
+ out = SQLString(
1622
+ out + _modifiers(
1623
+ nullable=nullable, default=default,
1624
+ collate=collate, charset=charset,
1625
+ ),
1626
+ )
1627
+ out.name = name
1628
+ return out
1629
+
1630
+
1631
+ def GEOGRAPHYPOINT(
1632
+ *,
1633
+ nullable: bool = True,
1634
+ default: Optional[str] = None,
1635
+ name: Optional[str] = None,
1636
+ ) -> SQLString:
1637
+ """
1638
+ GEOGRAPHYPOINT type specification.
1639
+
1640
+ Parameters
1641
+ ----------
1642
+ nullable : bool, optional
1643
+ Can the value be NULL?
1644
+ default : str, optional
1645
+ Default value
1646
+ name : str, optional
1647
+ Name of the column / parameter
1648
+
1649
+ Returns
1650
+ -------
1651
+ SQLString
1652
+
1653
+ """
1654
+ out = SQLString('GEOGRAPHYPOINT' + _modifiers(nullable=nullable, default=default))
1655
+ out.name = name
1656
+ return out
1657
+
1658
+
1659
+ def GEOGRAPHY(
1660
+ *,
1661
+ nullable: bool = True,
1662
+ default: Optional[str] = None,
1663
+ name: Optional[str] = None,
1664
+ ) -> SQLString:
1665
+ """
1666
+ GEOGRAPHYPOINT type specification.
1667
+
1668
+ Parameters
1669
+ ----------
1670
+ nullable : bool, optional
1671
+ Can the value be NULL?
1672
+ default : str, optional
1673
+ Default value
1674
+
1675
+ Returns
1676
+ -------
1677
+ str
1678
+
1679
+ """
1680
+ out = SQLString('GEOGRAPHY' + _modifiers(nullable=nullable, default=default))
1681
+ out.name = name
1682
+ return out
1683
+
1684
+
1685
+ # def RECORD(
1686
+ # *args: Tuple[str, DataType],
1687
+ # nullable: bool = True,
1688
+ # name: Optional[str] = None,
1689
+ # ) -> SQLString:
1690
+ # """
1691
+ # RECORD type specification.
1692
+ #
1693
+ # Parameters
1694
+ # ----------
1695
+ # *args : Tuple[str, DataType]
1696
+ # Field specifications
1697
+ # nullable : bool, optional
1698
+ # Can the value be NULL?
1699
+ # name : str, optional
1700
+ # Name of the column / parameter
1701
+ #
1702
+ # Returns
1703
+ # -------
1704
+ # SQLString
1705
+ #
1706
+ # """
1707
+ # assert len(args) > 0
1708
+ # fields = []
1709
+ # for name, value in args:
1710
+ # if callable(value):
1711
+ # fields.append(f'{escape_name(name)} {value()}')
1712
+ # else:
1713
+ # fields.append(f'{escape_name(name)} {value}')
1714
+ # out = SQLString(f'RECORD({", ".join(fields)})' + _modifiers(nullable=nullable))
1715
+ # out.name = name
1716
+ # return out
1717
+
1718
+
1719
+ # def ARRAY(
1720
+ # dtype: DataType,
1721
+ # nullable: bool = True,
1722
+ # name: Optional[str] = None,
1723
+ # ) -> SQLString:
1724
+ # """
1725
+ # ARRAY type specification.
1726
+ #
1727
+ # Parameters
1728
+ # ----------
1729
+ # dtype : DataType
1730
+ # The data type of the array elements
1731
+ # nullable : bool, optional
1732
+ # Can the value be NULL?
1733
+ # name : str, optional
1734
+ # Name of the column / parameter
1735
+ #
1736
+ # Returns
1737
+ # -------
1738
+ # SQLString
1739
+ #
1740
+ # """
1741
+ # if callable(dtype):
1742
+ # dtype = dtype()
1743
+ # out = SQLString(f'ARRAY({dtype})' + _modifiers(nullable=nullable))
1744
+ # out.name = name
1745
+ # return out
1746
+
1747
+
1748
+ # F32 = 'F32'
1749
+ # F64 = 'F64'
1750
+ # I8 = 'I8'
1751
+ # I16 = 'I16'
1752
+ # I32 = 'I32'
1753
+ # I64 = 'I64'
1754
+
1755
+
1756
+ # def VECTOR(
1757
+ # length: int,
1758
+ # element_type: str = F32,
1759
+ # *,
1760
+ # nullable: bool = True,
1761
+ # default: Optional[bytes] = None,
1762
+ # name: Optional[str] = None,
1763
+ # ) -> SQLString:
1764
+ # """
1765
+ # VECTOR type specification.
1766
+ #
1767
+ # Parameters
1768
+ # ----------
1769
+ # n : int
1770
+ # Number of elements in vector
1771
+ # element_type : str, optional
1772
+ # Type of the elements in the vector:
1773
+ # F32, F64, I8, I16, I32, I64
1774
+ # nullable : bool, optional
1775
+ # Can the value be NULL?
1776
+ # default : str, optional
1777
+ # Default value
1778
+ # name : str, optional
1779
+ # Name of the column / parameter
1780
+ #
1781
+ # Returns
1782
+ # -------
1783
+ # SQLString
1784
+ #
1785
+ # """
1786
+ # out = f'VECTOR({int(length)}, {element_type})'
1787
+ # out = SQLString(
1788
+ # out + _modifiers(
1789
+ # nullable=nullable, default=default,
1790
+ # ),
1791
+ # )
1792
+ # out.name = name
1793
+ # return out