drizzle-types 0.3.1

A type-safe SQL query builder for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
//! Traits that classify SQL type markers, so query builders can check
//! operations at compile time.
//!
//! Every expression carries a SQL type marker, a zero-sized type such as
//! [`postgres::types::Int4`](crate::postgres::types::Int4) or
//! [`sqlite::types::Text`](crate::sqlite::types::Text). The traits here say
//! what a marker can do:
//!
//! | Trait | Question it answers | Used for |
//! |---|---|---|
//! | [`DataType`] | Is this a SQL type marker? | every typed expression |
//! | [`Compatible`] | Can these two types be compared? | `eq`, `lt`, `IN`, `LIKE`, ... |
//! | [`Assignable`] | Can a value of this type be stored in that column? | bind values, `INSERT ... SELECT` |
//! | [`Numeric`] | Is it a number? | `+ - * /`, `SUM`, `AVG`, `ABS` |
//! | [`Integral`] | Is it an integer? | `LIMIT`/`OFFSET`, `SUBSTR` positions |
//! | [`Floating`] | Is it a floating-point number? | dialect type aliases |
//! | [`Textual`] | Is it a string? | `LIKE`, `UPPER`, `LENGTH`, `ILIKE`, regex |
//! | [`Binary`] | Is it raw bytes? | dialect type aliases |
//! | [`Temporal`] | Is it a date, time or timestamp? | date/time functions |
//! | [`BooleanLike`] | Can it be a condition? | `WHERE`, `AND`/`OR`/`NOT`, join `ON` |
//! | [`ArithmeticOutput`] / [`NegOutput`] | What type does arithmetic produce? | result type of `a + b`, `-a` |
//!
//! All traits are implemented by this crate for the dialect markers in
//! [`sqlite::types`](crate::sqlite::types), [`postgres::types`](crate::postgres::types)
//! and [`mysql::types`](crate::mysql::types). [`DataType`] is sealed, so
//! other crates cannot add new markers.
//!
//! # Examples
//!
//! Generic code can require a capability with a trait bound:
//!
//! ```
//! use drizzle_types::{Compatible, Numeric, postgres::types::{Float8, Int4, Text}};
//!
//! fn comparable<L: Compatible<R>, R: drizzle_types::DataType>() {}
//! fn numeric<T: Numeric>() {}
//!
//! comparable::<Int4, Float8>(); // int4 = float8 is allowed
//! numeric::<Int4>();
//! // numeric::<Text>(); // error: `Text` is not a numeric SQL type
//! # let _ = Text;
//! ```

use core::marker::PhantomData;

mod coerce;
mod ops;

pub use coerce::*;
pub use ops::*;

mod private {
    pub trait Sealed {}
}

/// A SQL type marker: a zero-sized type that stands for one SQL type.
///
/// Every typed expression names its SQL type through a `DataType`. This
/// crate implements it for each dialect marker (for example
/// [`postgres::types::Int4`](crate::postgres::types::Int4)), for
/// [`Array<T>`], [`Placeholder`], [`Conjunction`], and for tuples of markers
/// (row values such as `(a, b) IN (...)`; up to 8 elements by default, more
/// with the `col16` ... `col200` features).
///
/// The trait is sealed: other crates cannot implement it.
#[diagnostic::on_unimplemented(
    message = "`{Self}` is not a recognized SQL data type",
    label = "use a drizzle SQL type marker (Int, Text, Bool, etc.)"
)]
pub trait DataType: private::Sealed + Copy + 'static {}

/// Numeric SQL types: operands of arithmetic (`+`, `-`, `*`, `/`, `%`) and
/// numeric functions such as `SUM`, `AVG`, `ABS` and `ROUND`.
///
/// | Dialect | Markers |
/// |---|---|
/// | SQLite | `Integer`, `Real`, `Numeric`, `Any` |
/// | PostgreSQL | `Int2`, `Int4`, `Int8`, `Float4`, `Float8`, `Numeric` |
/// | MySQL | every integer marker (signed and unsigned), `Year`, `Float`, `Double`, `Decimal` |
///
/// Text, boolean, date and JSON markers are not numeric. The result type of an
/// operation comes from [`ArithmeticOutput`].
#[diagnostic::on_unimplemented(
    message = "`{Self}` is not a numeric SQL type",
    label = "arithmetic operations require Int, SmallInt, BigInt, Float, or Double"
)]
pub trait Numeric: DataType {}

/// Integer SQL types, required where SQL expects a whole number, such as
/// `LIMIT`/`OFFSET` and string positions.
///
/// | Dialect | Markers |
/// |---|---|
/// | SQLite | `Integer` |
/// | PostgreSQL | `Int2`, `Int4`, `Int8` |
/// | MySQL | every integer marker (signed and unsigned), `Year` |
///
/// Floating-point and decimal markers (`Real`, `Float8`, `Numeric`, ...) are not integral.
#[diagnostic::on_unimplemented(
    message = "`{Self}` is not an integer SQL type",
    label = "expected SmallInt, Int, or BigInt"
)]
pub trait Integral: Numeric {}

/// Floating-point SQL types.
///
/// | Dialect | Markers |
/// |---|---|
/// | SQLite | `Real` |
/// | PostgreSQL | `Float4` (`real`), `Float8` (`double precision`) |
/// | MySQL | `Float`, `Double` |
///
/// Exact decimals (`Numeric`, `Decimal`) are not floating.
#[diagnostic::on_unimplemented(
    message = "`{Self}` is not a floating-point SQL type",
    label = "expected Float or Double"
)]
pub trait Floating: Numeric {}

/// String SQL types: operands of `LIKE`, `ILIKE`, regex matching and string
/// functions such as `UPPER`, `LOWER`, `LENGTH` and `CONCAT`.
///
/// | Dialect | Markers |
/// |---|---|
/// | SQLite | `Text`, `Any` |
/// | PostgreSQL | `Text`, `Varchar`, `Char`, `Enum` |
/// | MySQL | `Char`, `Varchar`, `TinyText`, `Text`, `MediumText`, `LongText`, `Enum`, `Set` |
///
/// [`Placeholder`] is also textual, so a placeholder can be a pattern. JSON,
/// UUID and binary markers are not textual.
#[diagnostic::on_unimplemented(
    message = "`{Self}` is not a text SQL type",
    label = "expected Text or VarChar"
)]
pub trait Textual: DataType {}

/// Raw byte SQL types.
///
/// | Dialect | Markers |
/// |---|---|
/// | SQLite | `Blob` |
/// | PostgreSQL | `Bytea` |
/// | MySQL | `Binary`, `Varbinary`, `TinyBlob`, `Blob`, `MediumBlob`, `LongBlob`, `Bit` |
#[diagnostic::on_unimplemented(
    message = "`{Self}` is not a binary SQL type",
    label = "expected Bytes (BLOB/BYTEA)"
)]
pub trait Binary: DataType {}

/// Date and time SQL types: operands of date/time functions.
///
/// | Dialect | Markers |
/// |---|---|
/// | SQLite | `Integer`, `Real`, `Text`, `Numeric` (SQLite stores dates as Unix times, Julian days or ISO-8601 text) |
/// | PostgreSQL | `Date`, `Time`, `Timetz`, `Timestamp`, `Timestamptz`, `Interval` |
/// | MySQL | `Date`, `Time`, `DateTime`, `Timestamp` |
#[diagnostic::on_unimplemented(
    message = "`{Self}` is not a temporal SQL type",
    label = "expected Date, Time, Timestamp, or TimestampTz"
)]
pub trait Temporal: DataType {}

/// SQL types that can be used as a condition: in `WHERE`, `HAVING`, join
/// `ON`, `CASE WHEN`, and with `AND`, `OR` and `NOT`.
///
/// | Dialect | Markers |
/// |---|---|
/// | SQLite | `Integer` (SQLite has no boolean type; `0` is false) |
/// | PostgreSQL | `Boolean` |
/// | MySQL | `Boolean` |
///
/// [`Conjunction`], the type of a tuple of conditions, is also boolean-like.
/// Comparisons such as `eq` produce a boolean-like type, so they can be used
/// as conditions directly.
#[diagnostic::on_unimplemented(
    message = "`{Self}` is not a boolean SQL type",
    label = "logical operations require a boolean-typed expression"
)]
pub trait BooleanLike: DataType {}

/// SQL array type marker: `Array<T>` is an array whose elements have SQL type `T`.
///
/// Used for `PostgreSQL` array columns, such as `Array<Text>` for `text[]`.
/// `Array<T>` is [`Compatible`] and [`Assignable`] only with the same
/// `Array<T>`.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct Array<T: DataType>(pub PhantomData<T>);

/// SQL type of an untyped placeholder, whose value is bound when the query runs.
///
/// A placeholder has no known type yet, so it is [`Compatible`] with every
/// dialect marker in both directions and is [`Textual`]. This lets
/// `eq(column, Placeholder::named("id"))` compile for any column.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct Placeholder;

/// The SQL type of a condition list — a tuple of conditions combined with AND.
///
/// Boolean-like, so a condition list is accepted anywhere a condition is, but
/// deliberately **not** [`Compatible`] with
/// itself. A condition list occupies one expression slot rather than one column
/// slot, and self-incompatibility is what lets APIs that accept either a single
/// column or a tuple of columns (`IN (subquery)` row values) tell the two apart.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct Conjunction;

impl<T: DataType> private::Sealed for Array<T> {}
impl<T: DataType> DataType for Array<T> {}
impl private::Sealed for Placeholder {}
impl DataType for Placeholder {}
impl Textual for Placeholder {}
impl private::Sealed for Conjunction {}
impl DataType for Conjunction {}
impl BooleanLike for Conjunction {}

// =============================================================================
// SQLite dialect marker impls
// =============================================================================

impl private::Sealed for crate::sqlite::types::Integer {}
impl private::Sealed for crate::sqlite::types::Text {}
impl private::Sealed for crate::sqlite::types::Real {}
impl private::Sealed for crate::sqlite::types::Blob {}
impl private::Sealed for crate::sqlite::types::Numeric {}
impl private::Sealed for crate::sqlite::types::Any {}

impl DataType for crate::sqlite::types::Integer {}
impl DataType for crate::sqlite::types::Text {}
impl DataType for crate::sqlite::types::Real {}
impl DataType for crate::sqlite::types::Blob {}
impl DataType for crate::sqlite::types::Numeric {}
impl DataType for crate::sqlite::types::Any {}

impl Numeric for crate::sqlite::types::Integer {}
impl Numeric for crate::sqlite::types::Real {}
impl Numeric for crate::sqlite::types::Numeric {}
impl Numeric for crate::sqlite::types::Any {}

impl Integral for crate::sqlite::types::Integer {}

impl Floating for crate::sqlite::types::Real {}

impl Textual for crate::sqlite::types::Text {}
impl Textual for crate::sqlite::types::Any {}

impl Binary for crate::sqlite::types::Blob {}

impl Temporal for crate::sqlite::types::Integer {}
impl Temporal for crate::sqlite::types::Real {}
impl Temporal for crate::sqlite::types::Text {}
impl Temporal for crate::sqlite::types::Numeric {}

impl BooleanLike for crate::sqlite::types::Integer {}

// =============================================================================
// PostgreSQL dialect marker impls
// =============================================================================

impl private::Sealed for crate::postgres::types::Int2 {}
impl private::Sealed for crate::postgres::types::Int4 {}
impl private::Sealed for crate::postgres::types::Int8 {}
impl private::Sealed for crate::postgres::types::Float4 {}
impl private::Sealed for crate::postgres::types::Float8 {}
impl private::Sealed for crate::postgres::types::Varchar {}
impl private::Sealed for crate::postgres::types::Text {}
impl private::Sealed for crate::postgres::types::Char {}
impl private::Sealed for crate::postgres::types::Bytea {}
impl private::Sealed for crate::postgres::types::Boolean {}
impl private::Sealed for crate::postgres::types::Timestamptz {}
impl private::Sealed for crate::postgres::types::Timestamp {}
impl private::Sealed for crate::postgres::types::Date {}
impl private::Sealed for crate::postgres::types::Time {}
impl private::Sealed for crate::postgres::types::Timetz {}
impl private::Sealed for crate::postgres::types::Numeric {}
impl private::Sealed for crate::postgres::types::Uuid {}
impl private::Sealed for crate::postgres::types::Json {}
impl private::Sealed for crate::postgres::types::Jsonb {}
impl private::Sealed for crate::postgres::types::Any {}
impl private::Sealed for crate::postgres::types::Interval {}
impl private::Sealed for crate::postgres::types::Inet {}
impl private::Sealed for crate::postgres::types::Cidr {}
impl private::Sealed for crate::postgres::types::MacAddr {}
impl private::Sealed for crate::postgres::types::MacAddr8 {}
impl private::Sealed for crate::postgres::types::Point {}
impl private::Sealed for crate::postgres::types::LineString {}
impl private::Sealed for crate::postgres::types::Rect {}
impl private::Sealed for crate::postgres::types::BitString {}
impl private::Sealed for crate::postgres::types::Line {}
impl private::Sealed for crate::postgres::types::LineSegment {}
impl private::Sealed for crate::postgres::types::Polygon {}
impl private::Sealed for crate::postgres::types::Circle {}
impl private::Sealed for crate::postgres::types::Enum {}

impl DataType for crate::postgres::types::Int2 {}
impl DataType for crate::postgres::types::Int4 {}
impl DataType for crate::postgres::types::Int8 {}
impl DataType for crate::postgres::types::Float4 {}
impl DataType for crate::postgres::types::Float8 {}
impl DataType for crate::postgres::types::Varchar {}
impl DataType for crate::postgres::types::Text {}
impl DataType for crate::postgres::types::Char {}
impl DataType for crate::postgres::types::Bytea {}
impl DataType for crate::postgres::types::Boolean {}
impl DataType for crate::postgres::types::Timestamptz {}
impl DataType for crate::postgres::types::Timestamp {}
impl DataType for crate::postgres::types::Date {}
impl DataType for crate::postgres::types::Time {}
impl DataType for crate::postgres::types::Timetz {}
impl DataType for crate::postgres::types::Numeric {}
impl DataType for crate::postgres::types::Uuid {}
impl DataType for crate::postgres::types::Json {}
impl DataType for crate::postgres::types::Jsonb {}
impl DataType for crate::postgres::types::Any {}
impl DataType for crate::postgres::types::Interval {}
impl DataType for crate::postgres::types::Inet {}
impl DataType for crate::postgres::types::Cidr {}
impl DataType for crate::postgres::types::MacAddr {}
impl DataType for crate::postgres::types::MacAddr8 {}
impl DataType for crate::postgres::types::Point {}
impl DataType for crate::postgres::types::LineString {}
impl DataType for crate::postgres::types::Rect {}
impl DataType for crate::postgres::types::BitString {}
impl DataType for crate::postgres::types::Line {}
impl DataType for crate::postgres::types::LineSegment {}
impl DataType for crate::postgres::types::Polygon {}
impl DataType for crate::postgres::types::Circle {}
impl DataType for crate::postgres::types::Enum {}

impl Numeric for crate::postgres::types::Int2 {}
impl Numeric for crate::postgres::types::Int4 {}
impl Numeric for crate::postgres::types::Int8 {}
impl Numeric for crate::postgres::types::Float4 {}
impl Numeric for crate::postgres::types::Float8 {}
impl Numeric for crate::postgres::types::Numeric {}

impl Integral for crate::postgres::types::Int2 {}
impl Integral for crate::postgres::types::Int4 {}
impl Integral for crate::postgres::types::Int8 {}

impl Floating for crate::postgres::types::Float4 {}
impl Floating for crate::postgres::types::Float8 {}

impl Textual for crate::postgres::types::Varchar {}
impl Textual for crate::postgres::types::Text {}
impl Textual for crate::postgres::types::Char {}
impl Textual for crate::postgres::types::Enum {}

impl Binary for crate::postgres::types::Bytea {}

impl Temporal for crate::postgres::types::Timestamptz {}
impl Temporal for crate::postgres::types::Timestamp {}
impl Temporal for crate::postgres::types::Date {}
impl Temporal for crate::postgres::types::Time {}
impl Temporal for crate::postgres::types::Timetz {}

impl Temporal for crate::postgres::types::Interval {}

impl BooleanLike for crate::postgres::types::Boolean {}

// =============================================================================
// MySQL dialect marker impls
// =============================================================================

macro_rules! impl_mysql_data_types {
    ($($marker:ident),+ $(,)?) => {
        $(
            impl private::Sealed for crate::mysql::types::$marker {}
            impl DataType for crate::mysql::types::$marker {}
        )+
    };
}

impl_mysql_data_types!(
    TinyInt,
    TinyIntUnsigned,
    SmallInt,
    SmallIntUnsigned,
    MediumInt,
    MediumIntUnsigned,
    Int,
    IntUnsigned,
    BigInt,
    BigIntUnsigned,
    Float,
    Double,
    Decimal,
    Boolean,
    Char,
    Varchar,
    TinyText,
    Text,
    MediumText,
    LongText,
    Binary,
    Varbinary,
    TinyBlob,
    Blob,
    MediumBlob,
    LongBlob,
    Json,
    Date,
    Time,
    DateTime,
    Timestamp,
    Year,
    Enum,
    Set,
    Bit,
    Any,
);

macro_rules! impl_mysql_marker_trait {
    ($trait:ident; $($marker:ident),+ $(,)?) => {
        $(impl $trait for crate::mysql::types::$marker {})+
    };
}

impl_mysql_marker_trait!(Numeric;
    TinyInt,
    TinyIntUnsigned,
    SmallInt,
    SmallIntUnsigned,
    MediumInt,
    MediumIntUnsigned,
    Int,
    IntUnsigned,
    BigInt,
    BigIntUnsigned,
    Year,
    Float,
    Double,
    Decimal,
);

impl_mysql_marker_trait!(Integral;
    TinyInt,
    TinyIntUnsigned,
    SmallInt,
    SmallIntUnsigned,
    MediumInt,
    MediumIntUnsigned,
    Int,
    IntUnsigned,
    BigInt,
    BigIntUnsigned,
    Year,
);

impl Floating for crate::mysql::types::Float {}
impl Floating for crate::mysql::types::Double {}

impl_mysql_marker_trait!(Textual;
    Char, Varchar, TinyText, Text, MediumText, LongText, Enum, Set,
);

impl_mysql_marker_trait!(Binary; Binary, Varbinary, TinyBlob, Blob, MediumBlob, LongBlob, Bit,);

impl Temporal for crate::mysql::types::Date {}
impl Temporal for crate::mysql::types::Time {}
impl Temporal for crate::mysql::types::DateTime {}
impl Temporal for crate::mysql::types::Timestamp {}

impl BooleanLike for crate::mysql::types::Boolean {}

// =============================================================================
// Tuple SQL type markers
// =============================================================================

macro_rules! seq_tuples {
    (@acc $callback:ident [$($aT:ident),*] [$($ai:tt),*]) => {};
    (@acc $callback:ident [$($aT:ident),*] [$($ai:tt),*] ($T:ident, $i:tt) $($rest:tt)*) => {
        $callback!($($aT,)* $T; $($ai,)* $i);
        seq_tuples!(@acc $callback [$($aT,)* $T] [$($ai,)* $i] $($rest)*);
    };
    ($callback:ident; $($pairs:tt)+) => {
        seq_tuples!(@acc $callback [] [] $($pairs)+);
    };
    (@from $callback:ident [$($aT:ident),*] [$($ai:tt),*]; $($pairs:tt)+) => {
        seq_tuples!(@acc $callback [$($aT),*] [$($ai),*] $($pairs)+);
    };
}

macro_rules! with_col_sizes_8 {
    ($callback:ident) => {
        seq_tuples!($callback;
            (T0,0) (T1,1) (T2,2) (T3,3)
            (T4,4) (T5,5) (T6,6) (T7,7)
        );
    };
}

#[allow(unused_macros)]
macro_rules! with_col_sizes_16 {
    ($callback:ident) => {
        seq_tuples!(@from $callback
            [T0,T1,T2,T3,T4,T5,T6,T7]
            [0,1,2,3,4,5,6,7];
            (T8,8) (T9,9) (T10,10) (T11,11)
            (T12,12) (T13,13) (T14,14) (T15,15)
        );
    };
}

#[allow(unused_macros)]
macro_rules! with_col_sizes_32 {
    ($callback:ident) => {
        seq_tuples!(@from $callback
            [T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15]
            [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
            (T16,16) (T17,17) (T18,18) (T19,19)
            (T20,20) (T21,21) (T22,22) (T23,23)
            (T24,24) (T25,25) (T26,26) (T27,27)
            (T28,28) (T29,29) (T30,30) (T31,31)
        );
    };
}

#[allow(unused_macros)]
macro_rules! with_col_sizes_64 {
    ($callback:ident) => {
        seq_tuples!(@from $callback
            [T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,
             T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31]
            [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
             16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31];
            (T32,32) (T33,33) (T34,34) (T35,35)
            (T36,36) (T37,37) (T38,38) (T39,39)
            (T40,40) (T41,41) (T42,42) (T43,43)
            (T44,44) (T45,45) (T46,46) (T47,47)
            (T48,48) (T49,49) (T50,50) (T51,51)
            (T52,52) (T53,53) (T54,54) (T55,55)
            (T56,56) (T57,57) (T58,58) (T59,59)
            (T60,60) (T61,61) (T62,62) (T63,63)
        );
    };
}

#[allow(unused_macros)]
macro_rules! with_col_sizes_128 {
    ($callback:ident) => {
        seq_tuples!(@from $callback
            [T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,
             T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,
             T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,
             T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63]
            [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
             16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
             32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
             48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63];
            (T64,64) (T65,65) (T66,66) (T67,67)
            (T68,68) (T69,69) (T70,70) (T71,71)
            (T72,72) (T73,73) (T74,74) (T75,75)
            (T76,76) (T77,77) (T78,78) (T79,79)
            (T80,80) (T81,81) (T82,82) (T83,83)
            (T84,84) (T85,85) (T86,86) (T87,87)
            (T88,88) (T89,89) (T90,90) (T91,91)
            (T92,92) (T93,93) (T94,94) (T95,95)
            (T96,96) (T97,97) (T98,98) (T99,99)
            (T100,100) (T101,101) (T102,102) (T103,103)
            (T104,104) (T105,105) (T106,106) (T107,107)
            (T108,108) (T109,109) (T110,110) (T111,111)
            (T112,112) (T113,113) (T114,114) (T115,115)
            (T116,116) (T117,117) (T118,118) (T119,119)
            (T120,120) (T121,121) (T122,122) (T123,123)
            (T124,124) (T125,125) (T126,126) (T127,127)
        );
    };
}

#[allow(unused_macros)]
macro_rules! with_col_sizes_200 {
    ($callback:ident) => {
        seq_tuples!(@from $callback
            [T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,
             T16,T17,T18,T19,T20,T21,T22,T23,T24,T25,T26,T27,T28,T29,T30,T31,
             T32,T33,T34,T35,T36,T37,T38,T39,T40,T41,T42,T43,T44,T45,T46,T47,
             T48,T49,T50,T51,T52,T53,T54,T55,T56,T57,T58,T59,T60,T61,T62,T63,
             T64,T65,T66,T67,T68,T69,T70,T71,T72,T73,T74,T75,T76,T77,T78,T79,
             T80,T81,T82,T83,T84,T85,T86,T87,T88,T89,T90,T91,T92,T93,T94,T95,
             T96,T97,T98,T99,T100,T101,T102,T103,T104,T105,T106,T107,T108,T109,T110,T111,
             T112,T113,T114,T115,T116,T117,T118,T119,T120,T121,T122,T123,T124,T125,T126,T127]
            [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
             16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
             32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
             48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
             64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
             80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
             96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
             112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127];
            (T128,128) (T129,129) (T130,130) (T131,131)
            (T132,132) (T133,133) (T134,134) (T135,135)
            (T136,136) (T137,137) (T138,138) (T139,139)
            (T140,140) (T141,141) (T142,142) (T143,143)
            (T144,144) (T145,145) (T146,146) (T147,147)
            (T148,148) (T149,149) (T150,150) (T151,151)
            (T152,152) (T153,153) (T154,154) (T155,155)
            (T156,156) (T157,157) (T158,158) (T159,159)
            (T160,160) (T161,161) (T162,162) (T163,163)
            (T164,164) (T165,165) (T166,166) (T167,167)
            (T168,168) (T169,169) (T170,170) (T171,171)
            (T172,172) (T173,173) (T174,174) (T175,175)
            (T176,176) (T177,177) (T178,178) (T179,179)
            (T180,180) (T181,181) (T182,182) (T183,183)
            (T184,184) (T185,185) (T186,186) (T187,187)
            (T188,188) (T189,189) (T190,190) (T191,191)
            (T192,192) (T193,193) (T194,194) (T195,195)
            (T196,196) (T197,197) (T198,198) (T199,199)
        );
    };
}

macro_rules! impl_tuple_datatype {
    ($($T:ident),+; $($idx:tt),+) => {
        impl<$($T: DataType),+> private::Sealed for ($($T,)+) {}
        impl<$($T: DataType),+> DataType for ($($T,)+) {}
    };
}

with_col_sizes_8!(impl_tuple_datatype);

#[cfg(any(
    feature = "col16",
    feature = "col32",
    feature = "col64",
    feature = "col128",
    feature = "col200"
))]
with_col_sizes_16!(impl_tuple_datatype);

#[cfg(any(
    feature = "col32",
    feature = "col64",
    feature = "col128",
    feature = "col200"
))]
with_col_sizes_32!(impl_tuple_datatype);

#[cfg(any(feature = "col64", feature = "col128", feature = "col200"))]
with_col_sizes_64!(impl_tuple_datatype);

#[cfg(any(feature = "col128", feature = "col200"))]
with_col_sizes_128!(impl_tuple_datatype);

#[cfg(feature = "col200")]
with_col_sizes_200!(impl_tuple_datatype);

#[cfg(test)]
mod tests {
    use super::*;

    fn assert_data_type<T: DataType>() {}
    fn assert_integral<T: Integral>() {}
    fn assert_floating<T: Floating>() {}
    fn assert_textual<T: Textual>() {}
    fn assert_binary<T: Binary>() {}
    fn assert_temporal<T: Temporal>() {}
    fn assert_boolean_like<T: BooleanLike>() {}

    #[test]
    fn mysql_markers_have_their_expected_type_capabilities() {
        assert_data_type::<crate::mysql::types::Any>();
        assert_integral::<crate::mysql::types::IntUnsigned>();
        assert_integral::<crate::mysql::types::Year>();
        assert_floating::<crate::mysql::types::Float>();
        assert_floating::<crate::mysql::types::Double>();
        assert_textual::<crate::mysql::types::Enum>();
        assert_textual::<crate::mysql::types::Set>();
        assert_binary::<crate::mysql::types::Varbinary>();
        assert_binary::<crate::mysql::types::Bit>();
        assert_temporal::<crate::mysql::types::DateTime>();
        assert_boolean_like::<crate::mysql::types::Boolean>();
    }
}