singlestoredb 0.8.9__cp36-abi3-win_amd64.whl → 0.9.0__cp36-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of singlestoredb might be problematic. Click here for more details.

Files changed (37) hide show
  1. _singlestoredb_accel.pyd +0 -0
  2. singlestoredb/__init__.py +1 -1
  3. singlestoredb/exceptions.py +24 -0
  4. singlestoredb/functions/__init__.py +1 -0
  5. singlestoredb/functions/decorator.py +165 -0
  6. singlestoredb/functions/dtypes.py +1396 -0
  7. singlestoredb/functions/ext/__init__.py +2 -0
  8. singlestoredb/functions/ext/asgi.py +357 -0
  9. singlestoredb/functions/ext/json.py +49 -0
  10. singlestoredb/functions/ext/rowdat_1.py +111 -0
  11. singlestoredb/functions/signature.py +607 -0
  12. singlestoredb/management/billing_usage.py +148 -0
  13. singlestoredb/management/manager.py +42 -1
  14. singlestoredb/management/organization.py +85 -0
  15. singlestoredb/management/utils.py +118 -1
  16. singlestoredb/management/workspace.py +881 -5
  17. singlestoredb/mysql/__init__.py +12 -10
  18. singlestoredb/mysql/charset.py +12 -11
  19. singlestoredb/mysql/constants/CLIENT.py +0 -1
  20. singlestoredb/mysql/constants/COMMAND.py +0 -1
  21. singlestoredb/mysql/constants/CR.py +0 -2
  22. singlestoredb/mysql/constants/ER.py +0 -1
  23. singlestoredb/mysql/constants/FIELD_TYPE.py +0 -1
  24. singlestoredb/mysql/constants/FLAG.py +0 -1
  25. singlestoredb/mysql/constants/SERVER_STATUS.py +0 -1
  26. singlestoredb/mysql/converters.py +49 -28
  27. singlestoredb/mysql/err.py +3 -3
  28. singlestoredb/mysql/optionfile.py +4 -4
  29. singlestoredb/mysql/times.py +3 -4
  30. singlestoredb/tests/test2.sql +1 -0
  31. singlestoredb/tests/test_management.py +393 -3
  32. singlestoredb/tests/test_udf.py +698 -0
  33. {singlestoredb-0.8.9.dist-info → singlestoredb-0.9.0.dist-info}/METADATA +1 -1
  34. {singlestoredb-0.8.9.dist-info → singlestoredb-0.9.0.dist-info}/RECORD +37 -25
  35. {singlestoredb-0.8.9.dist-info → singlestoredb-0.9.0.dist-info}/LICENSE +0 -0
  36. {singlestoredb-0.8.9.dist-info → singlestoredb-0.9.0.dist-info}/WHEEL +0 -0
  37. {singlestoredb-0.8.9.dist-info → singlestoredb-0.9.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1396 @@
1
+ #!/usr/bin/env python3
2
+ import datetime
3
+ import decimal
4
+ import re
5
+ from typing import Any
6
+ from typing import Callable
7
+ from typing import Optional
8
+ from typing import Tuple
9
+ from typing import Union
10
+
11
+ from ..mysql.converters import escape_item # type: ignore
12
+
13
+
14
+ DataType = Union[str, Callable[..., Any]]
15
+
16
+
17
+ class NULL:
18
+ """NULL (for use in default values)."""
19
+ pass
20
+
21
+
22
+ def escape_name(name: str) -> str:
23
+ """Escape a function parameter name."""
24
+ if '`' in name:
25
+ name = name.replace('`', '``')
26
+ return f'`{name}`'
27
+
28
+
29
+ # charsets
30
+ utf8mb4 = 'utf8mb4'
31
+ utf8 = 'utf8'
32
+ binary = 'binary'
33
+
34
+ # collations
35
+ utf8_general_ci = 'utf8_general_ci'
36
+ utf8_bin = 'utf8_bin'
37
+ utf8_unicode_ci = 'utf8_unicode_ci'
38
+ utf8_icelandic_ci = 'utf8_icelandic_ci'
39
+ utf8_latvian_ci = 'utf8_latvian_ci'
40
+ utf8_romanian_ci = 'utf8_romanian_ci'
41
+ utf8_slovenian_ci = 'utf8_slovenian_ci'
42
+ utf8_polish_ci = 'utf8_polish_ci'
43
+ utf8_estonian_ci = 'utf8_estonian_ci'
44
+ utf8_spanish_ci = 'utf8_spanish_ci'
45
+ utf8_swedish_ci = 'utf8_swedish_ci'
46
+ utf8_turkish_ci = 'utf8_turkish_ci'
47
+ utf8_czech_ci = 'utf8_czech_ci'
48
+ utf8_danish_ci = 'utf8_danish_ci'
49
+ utf8_lithuanian_ci = 'utf8_lithuanian_ci'
50
+ utf8_slovak_ci = 'utf8_slovak_ci'
51
+ utf8_spanish2_ci = 'utf8_spanish2_ci'
52
+ utf8_roman_ci = 'utf8_roman_ci'
53
+ utf8_persian_ci = 'utf8_persian_ci'
54
+ utf8_esperanto_ci = 'utf8_esperanto_ci'
55
+ utf8_hungarian_ci = 'utf8_hungarian_ci'
56
+ utf8_sinhala_ci = 'utf8_sinhala_ci'
57
+ utf8mb4_general_ci = 'utf8mb4_general_ci'
58
+ utf8mb4_bin = 'utf8mb4_bin'
59
+ utf8mb4_unicode_ci = 'utf8mb4_unicode_ci'
60
+ utf8mb4_icelandic_ci = 'utf8mb4_icelandic_ci'
61
+ utf8mb4_latvian_ci = 'utf8mb4_latvian_ci'
62
+ utf8mb4_romanian_ci = 'utf8mb4_romanian_ci'
63
+ utf8mb4_slovenian_ci = 'utf8mb4_slovenian_ci'
64
+ utf8mb4_polish_ci = 'utf8mb4_polish_ci'
65
+ utf8mb4_estonian_ci = 'utf8mb4_estonian_ci'
66
+ utf8mb4_spanish_ci = 'utf8mb4_spanish_ci'
67
+ utf8mb4_swedish_ci = 'utf8mb4_swedish_ci'
68
+ utf8mb4_turkish_ci = 'utf8mb4_turkish_ci'
69
+ utf8mb4_czech_ci = 'utf8mb4_czech_ci'
70
+ utf8mb4_danish_ci = 'utf8mb4_danish_ci'
71
+ utf8mb4_lithuanian_ci = 'utf8mb4_lithuanian_ci'
72
+ utf8mb4_slovak_ci = 'utf8mb4_slovak_ci'
73
+ utf8mb4_spanish2_ci = 'utf8mb4_spanish2_ci'
74
+ utf8mb4_roman_ci = 'utf8mb4_roman_ci'
75
+ utf8mb4_persian_ci = 'utf8mb4_persian_ci'
76
+ utf8mb4_esperanto_ci = 'utf8mb4_esperanto_ci'
77
+ utf8mb4_hungarian_ci = 'utf8mb4_hungarian_ci'
78
+ utf8mb4_sinhala_ci = 'utf8mb4_sinhala_ci'
79
+
80
+
81
+ def _modifiers(
82
+ *,
83
+ nullable: Optional[bool] = None,
84
+ charset: Optional[str] = None,
85
+ collate: Optional[str] = None,
86
+ default: Optional[Any] = None,
87
+ unsigned: Optional[bool] = None,
88
+ ) -> str:
89
+ """
90
+ Format type modifiers.
91
+
92
+ Parameters
93
+ ----------
94
+ nullable : bool, optional
95
+ Can the value be NULL?
96
+ charset : str, optional
97
+ Character set
98
+ collate : str, optional
99
+ Collation
100
+ default ; Any, optional
101
+ Default value
102
+ unsigned : bool, optional
103
+ Is the value unsigned? (ints only)
104
+
105
+ Returns
106
+ -------
107
+ str
108
+
109
+ """
110
+ out = []
111
+
112
+ if unsigned is not None:
113
+ if unsigned:
114
+ out.append('UNSIGNED')
115
+
116
+ if charset is not None:
117
+ if not re.match(r'^[A-Za-z0-9_]+$', charset):
118
+ raise ValueError(f'charset value is invalid: {charset}')
119
+ out.append(f'CHARACTER SET {charset}')
120
+
121
+ if collate is not None:
122
+ if not re.match(r'^[A-Za-z0-9_]+$', collate):
123
+ raise ValueError(f'collate value is invalid: {collate}')
124
+ out.append(f'COLLATE {collate}')
125
+
126
+ if nullable is not None:
127
+ if nullable:
128
+ out.append('NULL')
129
+ else:
130
+ out.append('NOT NULL')
131
+
132
+ if default is NULL:
133
+ out.append('DEFAULT NULL')
134
+ elif default is not None:
135
+ out.append(f'DEFAULT {escape_item(default, "utf-8")}')
136
+
137
+ return ' ' + ' '.join(out)
138
+
139
+
140
+ def _bool(x: Optional[bool] = None) -> Optional[bool]:
141
+ """Cast bool."""
142
+ if x is None:
143
+ return None
144
+ return bool(x)
145
+
146
+
147
+ def BOOL(*, nullable: bool = False, default: Optional[bool] = None) -> str:
148
+ """
149
+ BOOL type specification.
150
+
151
+ Parameters
152
+ ----------
153
+ nullable : bool, optional
154
+ Can the value be NULL?
155
+ default : bool, optional
156
+ Default value
157
+
158
+ Returns
159
+ -------
160
+ str
161
+
162
+ """
163
+ return 'BOOL' + _modifiers(nullable=nullable, default=_bool(default))
164
+
165
+
166
+ def BOOLEAN(*, nullable: bool = False, default: Optional[bool] = None) -> str:
167
+ """
168
+ BOOLEAN type specification.
169
+
170
+ Parameters
171
+ ----------
172
+ nullable : bool, optional
173
+ Can the value be NULL?
174
+ default : bool, optional
175
+ Default value
176
+
177
+ Returns
178
+ -------
179
+ str
180
+
181
+ """
182
+ return 'BOOLEAN' + _modifiers(nullable=nullable, default=_bool(default))
183
+
184
+
185
+ def BIT(*, nullable: bool = False, default: Optional[int] = None) -> str:
186
+ """
187
+ BIT type specification.
188
+
189
+ Parameters
190
+ ----------
191
+ nullable : bool, optional
192
+ Can the value be NULL?
193
+ default : int, optional
194
+ Default value
195
+
196
+ Returns
197
+ -------
198
+ str
199
+
200
+ """
201
+ return 'BIT' + _modifiers(nullable=nullable, default=default)
202
+
203
+
204
+ def TINYINT(
205
+ display_width: Optional[int] = None,
206
+ *,
207
+ nullable: bool = False,
208
+ default: Optional[int] = None,
209
+ unsigned: bool = False,
210
+ ) -> str:
211
+ """
212
+ TINYINT type specification.
213
+
214
+ Parameters
215
+ ----------
216
+ display_width : int, optional
217
+ Display width used by some clients
218
+ nullable : bool, optional
219
+ Can the value be NULL?
220
+ default : int, optional
221
+ Default value
222
+ unsigned : bool, optional
223
+ Is the int unsigned?
224
+
225
+ Returns
226
+ -------
227
+ str
228
+
229
+ """
230
+ out = f'TINYINT({display_width})' if display_width else 'TINYINT'
231
+ return out + _modifiers(nullable=nullable, default=default, unsigned=unsigned)
232
+
233
+
234
+ def TINYINT_UNSIGNED(
235
+ display_width: Optional[int] = None,
236
+ *,
237
+ nullable: bool = False,
238
+ default: Optional[int] = None,
239
+ ) -> str:
240
+ """
241
+ TINYINT UNSIGNED type specification.
242
+
243
+ Parameters
244
+ ----------
245
+ display_width : int, optional
246
+ Display width used by some clients
247
+ nullable : bool, optional
248
+ Can the value be NULL?
249
+ default : int, optional
250
+ Default value
251
+
252
+ Returns
253
+ -------
254
+ str
255
+
256
+ """
257
+ out = f'TINYINT({display_width})' if display_width else 'TINYINT'
258
+ return out + _modifiers(nullable=nullable, default=default, unsigned=True)
259
+
260
+
261
+ def SMALLINT(
262
+ display_width: Optional[int] = None,
263
+ *,
264
+ nullable: bool = False,
265
+ default: Optional[int] = None,
266
+ unsigned: bool = False,
267
+ ) -> str:
268
+ """
269
+ SMALLINT type specification.
270
+
271
+ Parameters
272
+ ----------
273
+ display_width : int, optional
274
+ Display width used by some clients
275
+ nullable : bool, optional
276
+ Can the value be NULL?
277
+ default : int, optional
278
+ Default value
279
+ unsigned : bool, optional
280
+ Is the int unsigned?
281
+
282
+ Returns
283
+ -------
284
+ str
285
+
286
+ """
287
+ out = f'SMALLINT({display_width})' if display_width else 'SMALLINT'
288
+ return out + _modifiers(nullable=nullable, default=default, unsigned=unsigned)
289
+
290
+
291
+ def SMALLINT_UNSIGNED(
292
+ display_width: Optional[int] = None,
293
+ *,
294
+ nullable: bool = False,
295
+ default: Optional[int] = None,
296
+ ) -> str:
297
+ """
298
+ SMALLINT UNSIGNED type specification.
299
+
300
+ Parameters
301
+ ----------
302
+ display_width : int, optional
303
+ Display width used by some clients
304
+ nullable : bool, optional
305
+ Can the value be NULL?
306
+ default : int, optional
307
+ Default value
308
+
309
+ Returns
310
+ -------
311
+ str
312
+
313
+ """
314
+ out = f'SMALLINT({display_width})' if display_width else 'SMALLINT'
315
+ return out + _modifiers(nullable=nullable, default=default, unsigned=True)
316
+
317
+
318
+ def MEDIUMINT(
319
+ display_width: Optional[int] = None,
320
+ *,
321
+ nullable: bool = False,
322
+ default: Optional[int] = None,
323
+ unsigned: bool = False,
324
+ ) -> str:
325
+ """
326
+ MEDIUMINT type specification.
327
+
328
+ Parameters
329
+ ----------
330
+ display_width : int, optional
331
+ Display width used by some clients
332
+ nullable : bool, optional
333
+ Can the value be NULL?
334
+ default : int, optional
335
+ Default value
336
+ unsigned : bool, optional
337
+ Is the int unsigned?
338
+
339
+ Returns
340
+ -------
341
+ str
342
+
343
+ """
344
+ out = f'MEDIUMINT({display_width})' if display_width else 'MEDIUMINT'
345
+ return out + _modifiers(nullable=nullable, default=default, unsigned=unsigned)
346
+
347
+
348
+ def MEDIUMINT_UNSIGNED(
349
+ display_width: Optional[int] = None,
350
+ *,
351
+ nullable: bool = False,
352
+ default: Optional[int] = None,
353
+ ) -> str:
354
+ """
355
+ MEDIUMINT UNSIGNED type specification.
356
+
357
+ Parameters
358
+ ----------
359
+ display_width : int, optional
360
+ Display width used by some clients
361
+ nullable : bool, optional
362
+ Can the value be NULL?
363
+ default : int, optional
364
+ Default value
365
+
366
+ Returns
367
+ -------
368
+ str
369
+
370
+ """
371
+ out = f'MEDIUMINT({display_width})' if display_width else 'MEDIUMINT'
372
+ return out + _modifiers(nullable=nullable, default=default, unsigned=True)
373
+
374
+
375
+ def INT(
376
+ display_width: Optional[int] = None,
377
+ *,
378
+ nullable: bool = False,
379
+ default: Optional[int] = None,
380
+ unsigned: bool = False,
381
+ ) -> str:
382
+ """
383
+ INT type specification.
384
+
385
+ Parameters
386
+ ----------
387
+ display_width : int, optional
388
+ Display width used by some clients
389
+ nullable : bool, optional
390
+ Can the value be NULL?
391
+ default : int, optional
392
+ Default value
393
+ unsigned : bool, optional
394
+ Is the int unsigned?
395
+
396
+ Returns
397
+ -------
398
+ str
399
+
400
+ """
401
+ out = f'INT({display_width})' if display_width else 'INT'
402
+ return out + _modifiers(nullable=nullable, default=default, unsigned=unsigned)
403
+
404
+
405
+ def INT_UNSIGNED(
406
+ display_width: Optional[int] = None,
407
+ *,
408
+ nullable: bool = False,
409
+ default: Optional[int] = None,
410
+ ) -> str:
411
+ """
412
+ INT UNSIGNED type specification.
413
+
414
+ Parameters
415
+ ----------
416
+ display_width : int, optional
417
+ Display width used by some clients
418
+ nullable : bool, optional
419
+ Can the value be NULL?
420
+ default : int, optional
421
+ Default value
422
+
423
+ Returns
424
+ -------
425
+ str
426
+
427
+ """
428
+ out = f'INT({display_width})' if display_width else 'INT'
429
+ return out + _modifiers(nullable=nullable, default=default, unsigned=True)
430
+
431
+
432
+ def INTEGER(
433
+ display_width: Optional[int] = None,
434
+ *,
435
+ nullable: bool = False,
436
+ default: Optional[int] = None,
437
+ unsigned: bool = False,
438
+ ) -> str:
439
+ """
440
+ INTEGER type specification.
441
+
442
+ Parameters
443
+ ----------
444
+ display_width : int, optional
445
+ Display width used by some clients
446
+ nullable : bool, optional
447
+ Can the value be NULL?
448
+ default : int, optional
449
+ Default value
450
+ unsigned : bool, optional
451
+ Is the int unsigned?
452
+
453
+ Returns
454
+ -------
455
+ str
456
+
457
+ """
458
+ out = f'INTEGER({display_width})' if display_width else 'INTEGER'
459
+ return out + _modifiers(nullable=nullable, default=default, unsigned=unsigned)
460
+
461
+
462
+ def INTEGER_UNSIGNED(
463
+ display_width: Optional[int] = None,
464
+ *,
465
+ nullable: bool = False,
466
+ default: Optional[int] = None,
467
+ ) -> str:
468
+ """
469
+ INTEGER 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
+
480
+ Returns
481
+ -------
482
+ str
483
+
484
+ """
485
+ out = f'INTEGER({display_width})' if display_width else 'INTEGER'
486
+ return out + _modifiers(nullable=nullable, default=default, unsigned=True)
487
+
488
+
489
+ def BIGINT(
490
+ display_width: Optional[int] = None,
491
+ *,
492
+ nullable: bool = False,
493
+ default: Optional[int] = None,
494
+ unsigned: bool = False,
495
+ ) -> str:
496
+ """
497
+ BIGINT type specification.
498
+
499
+ Parameters
500
+ ----------
501
+ display_width : int, optional
502
+ Display width used by some clients
503
+ nullable : bool, optional
504
+ Can the value be NULL?
505
+ default : int, optional
506
+ Default value
507
+ unsigned : bool, optional
508
+ Is the int unsigned?
509
+
510
+ Returns
511
+ -------
512
+ str
513
+
514
+ """
515
+ out = f'BIGINT({display_width})' if display_width else 'BIGINT'
516
+ return out + _modifiers(nullable=nullable, default=default, unsigned=unsigned)
517
+
518
+
519
+ def BIGINT_UNSIGNED(
520
+ display_width: Optional[int] = None,
521
+ *,
522
+ nullable: bool = False,
523
+ default: Optional[int] = None,
524
+ ) -> str:
525
+ """
526
+ BIGINT UNSIGNED type specification.
527
+
528
+ Parameters
529
+ ----------
530
+ display_width : int, optional
531
+ Display width used by some clients
532
+ nullable : bool, optional
533
+ Can the value be NULL?
534
+ default : int, optional
535
+ Default value
536
+
537
+ Returns
538
+ -------
539
+ str
540
+
541
+ """
542
+ out = f'BIGINT({int(display_width)})' if display_width else 'BIGINT'
543
+ return out + _modifiers(nullable=nullable, default=default, unsigned=True)
544
+
545
+
546
+ def FLOAT(
547
+ display_decimals: Optional[int] = None,
548
+ *,
549
+ nullable: bool = False,
550
+ default: Optional[float] = None,
551
+ ) -> str:
552
+ """
553
+ FLOAT type specification.
554
+
555
+ Parameters
556
+ ----------
557
+ display_decimals : int, optional
558
+ Number of decimal places to display
559
+ nullable : bool, optional
560
+ Can the value be NULL?
561
+ default : float, optional
562
+ Default value
563
+
564
+ Returns
565
+ -------
566
+ str
567
+
568
+ """
569
+ out = f'FLOAT({int(display_decimals)})' if display_decimals else 'FLOAT'
570
+ return out + _modifiers(nullable=nullable, default=default)
571
+
572
+
573
+ def DOUBLE(
574
+ display_decimals: Optional[int] = None,
575
+ *,
576
+ nullable: bool = False,
577
+ default: Optional[float] = None,
578
+ ) -> str:
579
+ """
580
+ DOUBLE type specification.
581
+
582
+ Parameters
583
+ ----------
584
+ display_decimals : int, optional
585
+ Number of decimal places to display
586
+ nullable : bool, optional
587
+ Can the value be NULL?
588
+ default : float, optional
589
+ Default value
590
+
591
+ Returns
592
+ -------
593
+ str
594
+
595
+ """
596
+ out = f'DOUBLE({int(display_decimals)})' if display_decimals else 'DOUBLE'
597
+ return out + _modifiers(nullable=nullable, default=default)
598
+
599
+
600
+ def REAL(
601
+ display_decimals: Optional[int] = None,
602
+ *,
603
+ nullable: bool = False,
604
+ default: Optional[float] = None,
605
+ ) -> str:
606
+ """
607
+ REAL type specification.
608
+
609
+ Parameters
610
+ ----------
611
+ display_decimals : int, optional
612
+ Number of decimal places to display
613
+ nullable : bool, optional
614
+ Can the value be NULL?
615
+ default : float, optional
616
+ Default value
617
+
618
+ Returns
619
+ -------
620
+ str
621
+
622
+ """
623
+ out = f'REAL({int(display_decimals)})' if display_decimals else 'REAL'
624
+ return out + _modifiers(nullable=nullable, default=default)
625
+
626
+
627
+ def DECIMAL(
628
+ precision: int,
629
+ scale: int,
630
+ *,
631
+ nullable: bool = False,
632
+ default: Optional[Union[str, decimal.Decimal]] = None,
633
+ ) -> str:
634
+ """
635
+ DECIMAL type specification.
636
+
637
+ Parameters
638
+ ----------
639
+ precision : int
640
+ Decimal precision
641
+ scale : int
642
+ Decimal scale
643
+ nullable : bool, optional
644
+ Can the value be NULL?
645
+ default : str or decimal.Decimal, optional
646
+ Default value
647
+
648
+ Returns
649
+ -------
650
+ str
651
+
652
+ """
653
+ return f'DECIMAL({int(precision)}, {int(scale)})' + \
654
+ _modifiers(nullable=nullable, default=default)
655
+
656
+
657
+ def DEC(
658
+ precision: int,
659
+ scale: int,
660
+ *,
661
+ nullable: bool = False,
662
+ default: Optional[Union[str, decimal.Decimal]] = None,
663
+ ) -> str:
664
+ """
665
+ DEC type specification.
666
+
667
+ Parameters
668
+ ----------
669
+ precision : int
670
+ Decimal precision
671
+ scale : int
672
+ Decimal scale
673
+ nullable : bool, optional
674
+ Can the value be NULL?
675
+ default : str or decimal.Decimal, optional
676
+ Default value
677
+
678
+ Returns
679
+ -------
680
+ str
681
+
682
+ """
683
+ return f'DEC({int(precision)}, {int(scale)})' + \
684
+ _modifiers(nullable=nullable, default=default)
685
+
686
+
687
+ def FIXED(
688
+ precision: int,
689
+ scale: int,
690
+ *,
691
+ nullable: bool = False,
692
+ default: Optional[Union[str, decimal.Decimal]] = None,
693
+ ) -> str:
694
+ """
695
+ FIXED type specification.
696
+
697
+ Parameters
698
+ ----------
699
+ precision : int
700
+ Decimal precision
701
+ scale : int
702
+ Decimal scale
703
+ nullable : bool, optional
704
+ Can the value be NULL?
705
+ default : str or decimal.Decimal, optional
706
+ Default value
707
+
708
+ Returns
709
+ -------
710
+ str
711
+
712
+ """
713
+ return f'FIXED({int(precision)}, {int(scale)})' + \
714
+ _modifiers(nullable=nullable, default=default)
715
+
716
+
717
+ def NUMERIC(
718
+ precision: int,
719
+ scale: int,
720
+ *,
721
+ nullable: bool = False,
722
+ default: Optional[Union[str, decimal.Decimal]] = None,
723
+ ) -> str:
724
+ """
725
+ NUMERIC type specification.
726
+
727
+ Parameters
728
+ ----------
729
+ precision : int
730
+ Decimal precision
731
+ scale : int
732
+ Decimal scale
733
+ nullable : bool, optional
734
+ Can the value be NULL?
735
+ default : str or decimal.Decimal, optional
736
+ Default value
737
+
738
+ Returns
739
+ -------
740
+ str
741
+
742
+ """
743
+ return f'NUMERIC({int(precision)}, {int(scale)})' + \
744
+ _modifiers(nullable=nullable, default=default)
745
+
746
+
747
+ def DATE(
748
+ *,
749
+ nullable: bool = False,
750
+ default: Optional[Union[str, datetime.date]] = None,
751
+ ) -> str:
752
+ """
753
+ DATE type specification.
754
+
755
+ Parameters
756
+ ----------
757
+ nullable : bool, optional
758
+ Can the value be NULL?
759
+ default : str or datetime.date, optional
760
+ Default value
761
+
762
+ Returns
763
+ -------
764
+ str
765
+
766
+ """
767
+ return 'DATE' + _modifiers(nullable=nullable, default=default)
768
+
769
+
770
+ def TIME(
771
+ precision: Optional[int] = None,
772
+ *,
773
+ nullable: bool = False,
774
+ default: Optional[Union[str, datetime.timedelta]] = None,
775
+ ) -> str:
776
+ """
777
+ TIME type specification.
778
+
779
+ Parameters
780
+ ----------
781
+ precision : int, optional
782
+ Sub-second precision
783
+ nullable : bool, optional
784
+ Can the value be NULL?
785
+ default : str or datetime.timedelta, optional
786
+ Default value
787
+
788
+ Returns
789
+ -------
790
+ str
791
+
792
+ """
793
+ out = f'TIME({int(precision)})' if precision else 'TIME'
794
+ return out + _modifiers(nullable=nullable, default=default)
795
+
796
+
797
+ def DATETIME(
798
+ precision: Optional[int] = None,
799
+ *,
800
+ nullable: bool = False,
801
+ default: Optional[Union[str, datetime.datetime]] = None,
802
+ ) -> str:
803
+ """
804
+ DATETIME type specification.
805
+
806
+ Parameters
807
+ ----------
808
+ precision : int, optional
809
+ Sub-second precision
810
+ nullable : bool, optional
811
+ Can the value be NULL?
812
+ default : str or datetime.datetime, optional
813
+ Default value
814
+
815
+ Returns
816
+ -------
817
+ str
818
+
819
+ """
820
+ out = f'DATETIME({int(precision)})' if precision else 'DATETIME'
821
+ return out + _modifiers(nullable=nullable, default=default)
822
+
823
+
824
+ def TIMESTAMP(
825
+ precision: Optional[int] = None,
826
+ *,
827
+ nullable: bool = False,
828
+ default: Optional[Union[str, datetime.datetime]] = None,
829
+ ) -> str:
830
+ """
831
+ TIMESTAMP type specification.
832
+
833
+ Parameters
834
+ ----------
835
+ precision : int, optional
836
+ Sub-second precision
837
+ nullable : bool, optional
838
+ Can the value be NULL?
839
+ default : str or datetime.datetime, optional
840
+ Default value
841
+
842
+ Returns
843
+ -------
844
+ str
845
+
846
+ """
847
+ out = f'TIMESTAMP({int(precision)})' if precision else 'TIMESTAMP'
848
+ return out + _modifiers(nullable=nullable, default=default)
849
+
850
+
851
+ def YEAR(*, nullable: bool = False, default: Optional[int] = None) -> str:
852
+ """
853
+ YEAR type specification.
854
+
855
+ Parameters
856
+ ----------
857
+ nullable : bool, optional
858
+ Can the value be NULL?
859
+ default : int, optional
860
+ Default value
861
+
862
+ Returns
863
+ -------
864
+ str
865
+
866
+ """
867
+ return 'YEAR' + _modifiers(nullable=nullable, default=default)
868
+
869
+
870
+ def CHAR(
871
+ length: Optional[int] = None,
872
+ *,
873
+ nullable: bool = False,
874
+ default: Optional[str] = None,
875
+ collate: Optional[str] = None,
876
+ charset: Optional[str] = None,
877
+ ) -> str:
878
+ """
879
+ CHAR type specification.
880
+
881
+ Parameters
882
+ ----------
883
+ length : int, optional
884
+ Maximum string length
885
+ nullable : bool, optional
886
+ Can the value be NULL?
887
+ default : str, optional
888
+ Default value
889
+ collate : str, optional
890
+ Collation
891
+ charset : str, optional
892
+ Character set
893
+
894
+ Returns
895
+ -------
896
+ str
897
+
898
+ """
899
+ out = f'CHAR({int(length)})' if length else 'CHAR'
900
+ return out + _modifiers(
901
+ nullable=nullable, default=default,
902
+ collate=collate, charset=charset,
903
+ )
904
+
905
+
906
+ def VARCHAR(
907
+ length: Optional[int] = None,
908
+ *,
909
+ nullable: bool = False,
910
+ default: Optional[str] = None,
911
+ collate: Optional[str] = None,
912
+ charset: Optional[str] = None,
913
+ ) -> str:
914
+ """
915
+ VARCHAR type specification.
916
+
917
+ Parameters
918
+ ----------
919
+ length : int, optional
920
+ Maximum string length
921
+ nullable : bool, optional
922
+ Can the value be NULL?
923
+ default : str, optional
924
+ Default value
925
+ collate : str, optional
926
+ Collation
927
+ charset : str, optional
928
+ Character set
929
+
930
+ Returns
931
+ -------
932
+ str
933
+
934
+ """
935
+ out = f'VARCHAR({int(length)})' if length else 'VARCHAR'
936
+ return out + _modifiers(
937
+ nullable=nullable, default=default,
938
+ collate=collate, charset=charset,
939
+ )
940
+
941
+
942
+ def LONGTEXT(
943
+ length: Optional[int] = None,
944
+ *,
945
+ nullable: bool = False,
946
+ default: Optional[str] = None,
947
+ collate: Optional[str] = None,
948
+ charset: Optional[str] = None,
949
+ ) -> str:
950
+ """
951
+ LONGTEXT type specification.
952
+
953
+ Parameters
954
+ ----------
955
+ length : int, optional
956
+ Maximum string length
957
+ nullable : bool, optional
958
+ Can the value be NULL?
959
+ default : str, optional
960
+ Default value
961
+ collate : str, optional
962
+ Collation
963
+ charset : str, optional
964
+ Character set
965
+
966
+ Returns
967
+ -------
968
+ str
969
+
970
+ """
971
+ out = f'LONGTEXT({int(length)})' if length else 'LONGTEXT'
972
+ return out + _modifiers(
973
+ nullable=nullable, default=default,
974
+ collate=collate, charset=charset,
975
+ )
976
+
977
+
978
+ def MEDIUMTEXT(
979
+ length: Optional[int] = None,
980
+ *,
981
+ nullable: bool = False,
982
+ default: Optional[str] = None,
983
+ collate: Optional[str] = None,
984
+ charset: Optional[str] = None,
985
+ ) -> str:
986
+ """
987
+ MEDIUMTEXT type specification.
988
+
989
+ Parameters
990
+ ----------
991
+ length : int, optional
992
+ Maximum string length
993
+ nullable : bool, optional
994
+ Can the value be NULL?
995
+ default : str, optional
996
+ Default value
997
+ collate : str, optional
998
+ Collation
999
+ charset : str, optional
1000
+ Character set
1001
+
1002
+ Returns
1003
+ -------
1004
+ str
1005
+
1006
+ """
1007
+ out = f'MEDIUMTEXT({int(length)})' if length else 'MEDIUMTEXT'
1008
+ return out + _modifiers(
1009
+ nullable=nullable, default=default,
1010
+ collate=collate, charset=charset,
1011
+ )
1012
+
1013
+
1014
+ def TEXT(
1015
+ length: Optional[int] = None,
1016
+ *,
1017
+ nullable: bool = False,
1018
+ default: Optional[str] = None,
1019
+ collate: Optional[str] = None,
1020
+ charset: Optional[str] = None,
1021
+ ) -> str:
1022
+ """
1023
+ TEXT type specification.
1024
+
1025
+ Parameters
1026
+ ----------
1027
+ length : int, optional
1028
+ Maximum string length
1029
+ nullable : bool, optional
1030
+ Can the value be NULL?
1031
+ default : str, optional
1032
+ Default value
1033
+ collate : str, optional
1034
+ Collation
1035
+ charset : str, optional
1036
+ Character set
1037
+
1038
+ Returns
1039
+ -------
1040
+ str
1041
+
1042
+ """
1043
+ out = f'TEXT({int(length)})' if length else 'TEXT'
1044
+ return out + _modifiers(
1045
+ nullable=nullable, default=default,
1046
+ collate=collate, charset=charset,
1047
+ )
1048
+
1049
+
1050
+ def TINYTEXT(
1051
+ length: Optional[int] = None,
1052
+ *,
1053
+ nullable: bool = False,
1054
+ default: Optional[str] = None,
1055
+ collate: Optional[str] = None,
1056
+ charset: Optional[str] = None,
1057
+ ) -> str:
1058
+ """
1059
+ TINYTEXT type specification.
1060
+
1061
+ Parameters
1062
+ ----------
1063
+ length : int, optional
1064
+ Maximum string length
1065
+ nullable : bool, optional
1066
+ Can the value be NULL?
1067
+ default : str, optional
1068
+ Default value
1069
+ collate : str, optional
1070
+ Collation
1071
+ charset : str, optional
1072
+ Character set
1073
+
1074
+ Returns
1075
+ -------
1076
+ str
1077
+
1078
+ """
1079
+ out = f'TINYTEXT({int(length)})' if length else 'TINYTEXT'
1080
+ return out + _modifiers(
1081
+ nullable=nullable, default=default,
1082
+ collate=collate, charset=charset,
1083
+ )
1084
+
1085
+
1086
+ def BINARY(
1087
+ length: Optional[int] = None,
1088
+ *,
1089
+ nullable: bool = False,
1090
+ default: Optional[bytes] = None,
1091
+ collate: Optional[str] = None,
1092
+ ) -> str:
1093
+ """
1094
+ BINARY type specification.
1095
+
1096
+ Parameters
1097
+ ----------
1098
+ length : int, optional
1099
+ Maximum string length
1100
+ nullable : bool, optional
1101
+ Can the value be NULL?
1102
+ default : str, optional
1103
+ Default value
1104
+ collate : str, optional
1105
+ Collation
1106
+
1107
+ Returns
1108
+ -------
1109
+ str
1110
+
1111
+ """
1112
+ out = f'BINARY({int(length)})' if length else 'BINARY'
1113
+ return out + _modifiers(
1114
+ nullable=nullable, default=default, collate=collate,
1115
+ )
1116
+
1117
+
1118
+ def VARBINARY(
1119
+ length: Optional[int] = None,
1120
+ *,
1121
+ nullable: bool = False,
1122
+ default: Optional[bytes] = None,
1123
+ collate: Optional[str] = None,
1124
+ ) -> str:
1125
+ """
1126
+ VARBINARY type specification.
1127
+
1128
+ Parameters
1129
+ ----------
1130
+ length : int, optional
1131
+ Maximum string length
1132
+ nullable : bool, optional
1133
+ Can the value be NULL?
1134
+ default : str, optional
1135
+ Default value
1136
+ collate : str, optional
1137
+ Collation
1138
+
1139
+ Returns
1140
+ -------
1141
+ str
1142
+
1143
+ """
1144
+ out = f'VARBINARY({int(length)})' if length else 'VARBINARY'
1145
+ return out + _modifiers(
1146
+ nullable=nullable, default=default, collate=collate,
1147
+ )
1148
+
1149
+
1150
+ def LONGBLOB(
1151
+ length: Optional[int] = None,
1152
+ *,
1153
+ nullable: bool = False,
1154
+ default: Optional[bytes] = None,
1155
+ collate: Optional[str] = None,
1156
+ ) -> str:
1157
+ """
1158
+ LONGBLOB type specification.
1159
+
1160
+ Parameters
1161
+ ----------
1162
+ length : int, optional
1163
+ Maximum string length
1164
+ nullable : bool, optional
1165
+ Can the value be NULL?
1166
+ default : str, optional
1167
+ Default value
1168
+ collate : str, optional
1169
+ Collation
1170
+
1171
+ Returns
1172
+ -------
1173
+ str
1174
+
1175
+ """
1176
+ out = f'LONGBLOB({int(length)})' if length else 'LONGBLOB'
1177
+ return out + _modifiers(
1178
+ nullable=nullable, default=default, collate=collate,
1179
+ )
1180
+
1181
+
1182
+ def MEDIUMBLOB(
1183
+ length: Optional[int] = None,
1184
+ *,
1185
+ nullable: bool = False,
1186
+ default: Optional[bytes] = None,
1187
+ collate: Optional[str] = None,
1188
+ ) -> str:
1189
+ """
1190
+ MEDIUMBLOB type specification.
1191
+
1192
+ Parameters
1193
+ ----------
1194
+ length : int, optional
1195
+ Maximum string length
1196
+ nullable : bool, optional
1197
+ Can the value be NULL?
1198
+ default : str, optional
1199
+ Default value
1200
+ collate : str, optional
1201
+ Collation
1202
+
1203
+ Returns
1204
+ -------
1205
+ str
1206
+
1207
+ """
1208
+ out = f'MEDIUMBLOB({int(length)})' if length else 'MEDIUMBLOB'
1209
+ return out + _modifiers(
1210
+ nullable=nullable, default=default, collate=collate,
1211
+ )
1212
+
1213
+
1214
+ def BLOB(
1215
+ length: Optional[int] = None,
1216
+ *,
1217
+ nullable: bool = False,
1218
+ default: Optional[bytes] = None,
1219
+ collate: Optional[str] = None,
1220
+ ) -> str:
1221
+ """
1222
+ BLOB type specification.
1223
+
1224
+ Parameters
1225
+ ----------
1226
+ length : int, optional
1227
+ Maximum string length
1228
+ nullable : bool, optional
1229
+ Can the value be NULL?
1230
+ default : str, optional
1231
+ Default value
1232
+ collate : str, optional
1233
+ Collation
1234
+
1235
+ Returns
1236
+ -------
1237
+ str
1238
+
1239
+ """
1240
+ out = f'BLOB({int(length)})' if length else 'BLOB'
1241
+ return out + _modifiers(
1242
+ nullable=nullable, default=default, collate=collate,
1243
+ )
1244
+
1245
+
1246
+ def TINYBLOB(
1247
+ length: Optional[int] = None,
1248
+ *,
1249
+ nullable: bool = False,
1250
+ default: Optional[bytes] = None,
1251
+ collate: Optional[str] = None,
1252
+ ) -> str:
1253
+ """
1254
+ TINYBLOB type specification.
1255
+
1256
+ Parameters
1257
+ ----------
1258
+ length : int, optional
1259
+ Maximum string length
1260
+ nullable : bool, optional
1261
+ Can the value be NULL?
1262
+ default : str, optional
1263
+ Default value
1264
+ collate : str, optional
1265
+ Collation
1266
+
1267
+ Returns
1268
+ -------
1269
+ str
1270
+
1271
+ """
1272
+ out = f'TINYBLOB({int(length)})' if length else 'TINYBLOB'
1273
+ return out + _modifiers(
1274
+ nullable=nullable, default=default, collate=collate,
1275
+ )
1276
+
1277
+
1278
+ def JSON(
1279
+ length: Optional[int] = None,
1280
+ *,
1281
+ nullable: bool = False,
1282
+ default: Optional[str] = None,
1283
+ collate: Optional[str] = None,
1284
+ charset: Optional[str] = None,
1285
+ ) -> str:
1286
+ """
1287
+ JSON type specification.
1288
+
1289
+ Parameters
1290
+ ----------
1291
+ length : int, optional
1292
+ Maximum string length
1293
+ nullable : bool, optional
1294
+ Can the value be NULL?
1295
+ default : str, optional
1296
+ Default value
1297
+ collate : str, optional
1298
+ Collation
1299
+ charset : str, optional
1300
+ Character set
1301
+
1302
+ Returns
1303
+ -------
1304
+ str
1305
+
1306
+ """
1307
+ out = f'JSON({int(length)})' if length else 'JSON'
1308
+ return out + _modifiers(
1309
+ nullable=nullable, default=default,
1310
+ collate=collate, charset=charset,
1311
+ )
1312
+
1313
+
1314
+ def GEOGRAPHYPOINT(*, nullable: bool = False, default: Optional[str] = None) -> str:
1315
+ """
1316
+ GEOGRAPHYPOINT type specification.
1317
+
1318
+ Parameters
1319
+ ----------
1320
+ nullable : bool, optional
1321
+ Can the value be NULL?
1322
+ default : str, optional
1323
+ Default value
1324
+
1325
+ Returns
1326
+ -------
1327
+ str
1328
+
1329
+ """
1330
+ return 'GEOGRAPHYPOINT' + _modifiers(nullable=nullable, default=default)
1331
+
1332
+
1333
+ def GEOGRAPHY(*, nullable: bool = False, default: Optional[str] = None) -> str:
1334
+ """
1335
+ GEOGRAPHYPOINT type specification.
1336
+
1337
+ Parameters
1338
+ ----------
1339
+ nullable : bool, optional
1340
+ Can the value be NULL?
1341
+ default : str, optional
1342
+ Default value
1343
+
1344
+ Returns
1345
+ -------
1346
+ str
1347
+
1348
+ """
1349
+ return 'GEOGRAPHY' + _modifiers(nullable=nullable, default=default)
1350
+
1351
+
1352
+ def RECORD(*args: Tuple[str, DataType], nullable: bool = False) -> str:
1353
+ """
1354
+ RECORD type specification.
1355
+
1356
+ Parameters
1357
+ ----------
1358
+ *args : Tuple[str, DataType]
1359
+ Field specifications
1360
+ nullable : bool, optional
1361
+ Can the value be NULL?
1362
+
1363
+ Returns
1364
+ -------
1365
+ str
1366
+
1367
+ """
1368
+ assert len(args) > 0
1369
+ fields = []
1370
+ for name, value in args:
1371
+ if callable(value):
1372
+ fields.append(f'{escape_name(name)} {value()}')
1373
+ else:
1374
+ fields.append(f'{escape_name(name)} {value}')
1375
+ return f'RECORD({", ".join(fields)})' + _modifiers(nullable=nullable)
1376
+
1377
+
1378
+ def ARRAY(dtype: DataType, nullable: bool = False) -> str:
1379
+ """
1380
+ ARRAY type specification.
1381
+
1382
+ Parameters
1383
+ ----------
1384
+ dtype : DataType
1385
+ The data type of the array elements
1386
+ nullable : bool, optional
1387
+ Can the value be NULL?
1388
+
1389
+ Returns
1390
+ -------
1391
+ str
1392
+
1393
+ """
1394
+ if callable(dtype):
1395
+ dtype = dtype()
1396
+ return f'ARRAY({dtype})' + _modifiers(nullable=nullable)