Skip to main content

diesel/type_impls/
tuples.rs

1use crate::associations::BelongsTo;
2use crate::backend::Backend;
3use crate::deserialize::{
4    self, CompatibleTupleElement, FromSqlRow, FromStaticSqlRow, Queryable, SqlTypeLikeMarker,
5    StaticallySizedRow,
6};
7use crate::expression::{
8    AppearsOnTable, Expression, IsContainedInGroupBy, MixedAggregates, QueryMetadata, Selectable,
9    SelectableExpression, TypedExpressionType, ValidGrouping, is_contained_in_group_by,
10};
11use crate::insertable::{CanInsertInSingleQuery, InsertValues, Insertable, InsertableOptionHelper};
12#[cfg(any(
13    feature = "__sqlite-shared",
14    feature = "postgres_backend",
15    feature = "mysql_backend",
16    feature = "mariadb_backend"
17))]
18use crate::query_builder::update_statement::batch_update::{BatchKeyHelper, BatchValueHelper};
19use crate::query_builder::*;
20use crate::query_dsl::load_dsl::CompatibleType;
21use crate::query_source::*;
22use crate::result::QueryResult;
23use crate::row::*;
24use crate::sql_types::{HasSqlType, IntoNullable, Nullable, OneIsNullable, SqlType};
25use crate::util::{TupleAppend, TupleSize};
26use alloc::vec::Vec;
27
28impl<T> TupleSize for T
29where
30    T: crate::sql_types::SingleValue,
31{
32    const SIZE: usize = 1;
33}
34
35macro_rules! fake_variadic {
36    (1i32 -> $($tt: tt)*) => {
37        #[cfg_attr(diesel_docsrs, doc(fake_variadic))]
38        $($tt)*
39    };
40    ($idx:tt -> $($tt: tt)*) => {
41        #[cfg_attr(diesel_docsrs, doc(hidden))]
42        $($tt)*
43    };
44}
45
46macro_rules! tuple_impls {
47    ($(
48        $Tuple:tt {
49            $(($idx:tt) -> $T:ident, $ST:ident, $TT:ident,)+
50        }
51    )+) => {
52        $(
53            fake_variadic!{
54                $Tuple ->
55                impl<$($T),+, __DB> HasSqlType<($($T,)+)> for __DB where
56                    $(__DB: HasSqlType<$T>),+,
57                    __DB: Backend,
58                {
59                    fn metadata(_: &mut __DB::MetadataLookup) -> __DB::TypeMetadata {
60                        unreachable!("Tuples should never implement `ToSql` directly");
61                    }
62                }
63            }
64
65            impl_from_sql_row!(($($T,)+), ($($ST,)+));
66
67
68            fake_variadic! {
69                $Tuple ->
70                #[diagnostic::do_not_recommend]
71                impl<$($T: Expression),+> Expression for ($($T,)+)
72                where ($($T::SqlType, )*): TypedExpressionType
73                {
74                    type SqlType = ($(<$T as Expression>::SqlType,)+);
75                }
76            }
77            fake_variadic! {
78                $Tuple -> impl<$($T: TypedExpressionType,)*> TypedExpressionType for ($($T,)*) {}
79            }
80            fake_variadic! {
81                $Tuple ->
82                impl<$($T: SqlTypeLikeMarker + TypedExpressionType,)*> TypedExpressionType for Nullable<($($T,)*)>
83                where ($($T,)*): SqlTypeLikeMarker
84                {
85                }
86            }
87            fake_variadic! {
88                $Tuple ->
89                impl<$($T: SqlTypeLikeMarker,)*> IntoNullable for ($($T,)*)
90                where Self: SqlTypeLikeMarker,
91                {
92                    type Nullable = Nullable<($($T,)*)>;
93                }
94            }
95
96            fake_variadic! {
97                $Tuple ->
98                impl<$($T,)+ __DB> Selectable<__DB> for ($($T,)+)
99                where
100                    __DB: Backend,
101                $($T: Selectable<__DB>),+,
102                {
103                    type SelectExpression = ($($T::SelectExpression,)+);
104
105                    fn construct_selection() -> Self::SelectExpression {
106                        ($($T::construct_selection(),)+)
107                    }
108                }
109            }
110
111            fake_variadic! {
112                $Tuple ->
113                impl<$($T: QueryFragment<__DB>),+, __DB: Backend> QueryFragment<__DB> for ($($T,)+) {
114                    #[allow(unused_assignments)]
115                    fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, __DB>) -> QueryResult<()>
116                    {
117                        let mut needs_comma = false;
118                        $(
119                            if !self.$idx.is_noop(out.backend())? {
120                                if needs_comma {
121                                    out.push_sql(", ");
122                                }
123                                self.$idx.walk_ast(out.reborrow())?;
124                                needs_comma = true;
125                            }
126                        )+
127                            Ok(())
128                    }
129                }
130            }
131
132            // cannot use `#[diagnostic::do_not_recommend]` here yet to hide tuple impls
133            // as this makes the error message worse (not saying which column is problematic)
134            impl<$($T,)+ Tab> ColumnList for ($($T,)+)
135            where
136                $($T: ColumnList<Table = Tab>,)+
137            {
138                type Table = Tab;
139
140                fn walk_ast<__DB: Backend>(&self, mut out: AstPass<'_, '_, __DB>) -> QueryResult<()> {
141                    $(
142                        if $idx != 0 {
143                            out.push_sql(", ");
144                        }
145                        self.$idx.walk_ast(out.reborrow())?;
146                    )+
147                    Ok(())
148                }
149            }
150
151            fake_variadic! {
152                $Tuple ->
153                impl<$($T: QueryId),+> QueryId for ($($T,)+) {
154                    type QueryId = ($($T::QueryId,)+);
155
156                    const HAS_STATIC_QUERY_ID: bool = $($T::HAS_STATIC_QUERY_ID &&)+ true;
157                }
158            }
159
160            impl_valid_grouping_for_tuple_of_columns!($($T,)*);
161
162            impl<$($T,)+ Tab> UndecoratedInsertRecord<Tab> for ($($T,)+)
163            where
164                $($T: UndecoratedInsertRecord<Tab>,)+
165            {
166            }
167
168            impl<$($T,)+ __DB> CanInsertInSingleQuery<__DB> for ($($T,)+)
169            where
170                __DB: Backend,
171                $($T: CanInsertInSingleQuery<__DB>,)+
172            {
173                fn rows_to_insert(&self) -> Option<usize> {
174                    $(debug_assert_eq!(self.$idx.rows_to_insert(), Some(1));)+
175                    Some(1)
176                }
177            }
178
179            fake_variadic! {
180                $Tuple ->
181                impl<$($T,)+ $($ST,)+ Tab> Insertable<Tab> for ($($T,)+)
182                where
183                    $($T: Insertable<Tab, Values = ValuesClause<$ST, Tab>>,)+
184                {
185                    type Values = ValuesClause<($($ST,)+), Tab>;
186
187                    fn values(self) -> Self::Values {
188                        ValuesClause::new(($(self.$idx.values().values,)+))
189                    }
190                }
191            }
192
193            // that isn't supported by the derive yet?
194            // fake_variadic! {
195            //     $Tuple ->
196                impl<'a, $($T,)+ Tab> Insertable<Tab> for &'a ($($T,)+)
197                where
198                    ($(&'a $T,)+): Insertable<Tab>,
199                {
200                    type Values = <($(&'a $T,)+) as Insertable<Tab>>::Values;
201
202                    fn values(self) -> Self::Values {
203                        ($(&self.$idx,)+).values()
204                    }
205                }
206//            }
207
208            #[allow(unused_assignments)]
209            impl<$($T,)+ Tab, __DB> InsertValues<__DB, Tab> for ($($T,)+)
210            where
211                Tab: Table,
212                __DB: Backend,
213                $($T: InsertValues<__DB, Tab>,)+
214            {
215                fn column_names(&self, mut out: AstPass<'_, '_, __DB>) -> QueryResult<()> {
216                    let mut needs_comma = false;
217                    $(
218                        let noop_element = self.$idx.is_noop(out.backend())?;
219                        if !noop_element {
220                            if needs_comma {
221                                out.push_sql(", ");
222                            }
223                            self.$idx.column_names(out.reborrow())?;
224                            needs_comma = true;
225                        }
226                    )+
227                    Ok(())
228                }
229            }
230
231            impl<__T, $($ST,)* Tab> Insertable<Tab> for InsertableOptionHelper<__T, ($($ST,)*)>
232            where
233                __T: Insertable<Tab>,
234                __T::Values: Default,
235            {
236                type Values = __T::Values;
237
238                fn values(self) -> Self::Values {
239                    self.0.map(|v| v.values()).unwrap_or_default()
240                }
241            }
242
243            // not possible to use diagnostic::do_not_recommend to hide the tuple impls
244            // yet as it gives worse error messages
245            // (doesn't show anymore which tuple element doesn't implement the trait)
246            impl<$($T,)+ QS> SelectableExpression<QS> for ($($T,)+) where
247                $($T: SelectableExpression<QS>,)+
248                ($($T,)+): AppearsOnTable<QS>,
249            {
250            }
251
252            fake_variadic! {
253                $Tuple ->
254                impl<$($T,)+ QS> AppearsOnTable<QS> for ($($T,)+) where
255                    $($T: AppearsOnTable<QS>,)+
256                    ($($T,)+): Expression,
257                {
258                }
259            }
260
261            #[cfg(any(feature = "__sqlite-shared", feature = "postgres_backend", feature = "mysql_backend", feature = "mariadb_backend"))]
262            impl<$($T,)+  __DB> BatchValueHelper<__DB> for ($($T,)+)
263            where
264                $($T: BatchValueHelper<__DB>,)+
265                __DB: Backend
266            {
267                fn assign<'b>(&'b self, mut out: AstPass<'_, 'b, __DB>) -> QueryResult<()> {
268                     $(
269                        if $idx != 0 {
270                            out.push_sql(", ");
271                        }
272                        self.$idx.assign(out.reborrow())?;
273                    )+
274                    Ok(())
275                }
276                fn column_name<'b>(&'b self, mut out: AstPass<'_, 'b, __DB>) -> QueryResult<()> {
277                     $(
278                        if $idx != 0 {
279                            out.push_sql(", ");
280                        }
281                        self.$idx.column_name(out.reborrow())?;
282                    )+
283                    Ok(())
284                }
285                fn bind_value<'b>(&'b self, mut out: AstPass<'_, 'b, __DB>) -> QueryResult<()> {
286                    $(
287                        if $idx != 0 {
288                            out.push_sql(", ");
289                        }
290                        self.$idx.bind_value(out.reborrow())?;
291                    )+
292                    Ok(())
293                }
294            }
295
296            #[cfg(any(feature = "__sqlite-shared", feature = "postgres_backend", feature = "mysql_backend", feature = "mariadb_backend"))]
297            impl<$($T,)+ $($ST,)+ __DB> BatchKeyHelper<($($ST,)*), __DB> for ($($T,)+)
298            where
299                __DB: Backend,
300               $($T: BatchKeyHelper<$ST, __DB>,)+
301            {
302                fn bind_value<'b>(&'b self, mut out: AstPass<'_, 'b, __DB>) -> QueryResult<()> {
303                    $(
304                        if $idx != 0 {
305                            out.push_sql(", ");
306                        }
307                        self.$idx.bind_value(out.reborrow())?;
308                    )+
309                    Ok(())
310                }
311
312                fn column_name<'b>(&'b self, mut out: AstPass<'_, 'b, __DB>) -> QueryResult<()> {
313                     $(
314                        if $idx != 0 {
315                            out.push_sql(", ");
316                        }
317                        self.$idx.column_name(out.reborrow())?;
318                    )+
319                    Ok(())
320                }
321
322                fn assign<'b>(pk: &'b ($($ST,)+), mut out: AstPass<'_, 'b, __DB>) -> QueryResult<()> {
323                    $(
324                        if $idx != 0 {
325                            out.push_sql(" AND ");
326                        }
327                        <$T as BatchKeyHelper<$ST, __DB>>::assign(&pk.$idx, out.reborrow())?;
328                    )+
329                    Ok(())
330                }
331            }
332
333            impl<$($T,)* W> crate::query_builder::update_statement::private::AllowFilterForUpdate<crate::query_builder::where_clause::WhereClause<W>>
334                for ($($T,)*)
335            where $($T: crate::query_builder::update_statement::private::AllowFilterForUpdate<crate::query_builder::where_clause::WhereClause<W>>,)* {
336            }
337
338            impl<'a, $($T,)* DB> crate::query_builder::update_statement::private::AllowFilterForUpdate<crate::query_builder::where_clause::BoxedWhereClause<'a, DB>>
339                for ($($T,)*)
340            where
341                DB: crate::backend::Backend,
342                $($T: crate::query_builder::update_statement::private::AllowFilterForUpdate<crate::query_builder::where_clause::BoxedWhereClause<'a, DB>>,)* {
343            }
344
345            impl<'a, $($T,)*> crate::query_builder::update_statement::changeset::IntoOwned for ($(&'a $T,)*)
346            where $(&'a $T: crate::query_builder::update_statement::changeset::IntoOwned,)*
347            {
348                type Owned = ($(<&'a $T as crate::query_builder::update_statement::changeset::IntoOwned>::Owned,)*);
349
350                fn into_owned(self) -> Self::Owned {
351                    ($(<&'a $T as crate::query_builder::update_statement::changeset::IntoOwned>::into_owned(&self.$idx),)*)
352                }
353            }
354
355            fake_variadic! {
356                $Tuple ->
357                impl<Target, $($T,)+> AsChangeset for ($($T,)+) where
358                    $($T: AsChangeset<Target=Target>,)+
359                    Target: QuerySource,
360                {
361                    type Target = Target;
362                    type Changeset = ($($T::Changeset,)+);
363
364                    fn as_changeset(self) -> Self::Changeset {
365                        ($(self.$idx.as_changeset(),)+)
366                    }
367                }
368            }
369
370            fake_variadic! {
371                $Tuple ->
372                impl<$($T,)+ Parent> BelongsTo<Parent> for ($($T,)+) where
373                    T: BelongsTo<Parent>,
374                {
375                    type ForeignKey = T::ForeignKey;
376                    type ForeignKeyColumn = T::ForeignKeyColumn;
377
378                    fn foreign_key(&self) -> Option<&Self::ForeignKey> {
379                        self.0.foreign_key()
380                    }
381
382                    fn foreign_key_column() -> Self::ForeignKeyColumn {
383                        T::foreign_key_column()
384                    }
385                }
386            }
387
388            impl<$($T,)+ Next> TupleAppend<Next> for ($($T,)+) {
389                type Output = ($($T,)+ Next);
390
391                #[allow(non_snake_case)]
392                fn tuple_append(self, next: Next) -> Self::Output {
393                    let ($($T,)+) = self;
394                    ($($T,)+ next)
395                }
396            }
397
398            impl_sql_type!($($T,)*);
399
400            fake_variadic! {
401                $Tuple ->
402                impl<$($T,)* __DB, $($ST,)*> Queryable<($($ST,)*), __DB> for ($($T,)*)
403                where __DB: Backend,
404                      Self: FromStaticSqlRow<($($ST,)*), __DB>,
405                {
406                    type Row = Self;
407
408                    fn build(row: Self::Row) -> deserialize::Result<Self> {
409                        Ok(row)
410                    }
411                }
412            }
413
414            // That's unfortunally not supported yet
415            // fake_variadic! {
416            //     $Tuple ->
417                impl<__T, $($ST,)*  __DB> FromStaticSqlRow<Nullable<($($ST,)*)>, __DB> for Option<__T> where
418                    __DB: Backend,
419                ($($ST,)*): SqlType,
420                    __T: FromSqlRow<($($ST,)*), __DB>,
421                {
422
423                    #[allow(non_snake_case, unused_variables, unused_mut)]
424                    fn build_from_row<'a>(row: &impl Row<'a, __DB>)
425                                          -> deserialize::Result<Self>
426                    {
427                        match <__T as FromSqlRow<($($ST,)*), __DB>>::build_from_row(row) {
428                            Ok(v) => Ok(Some(v)),
429                            Err(e) if e.is::<crate::result::UnexpectedNullError>() => Ok(None),
430                            Err(e) => Err(e)
431                        }
432                    }
433                }
434            //}
435
436            // That's unfortunally not supported yet
437            // fake_variadic! {
438            //     $Tuple ->
439                impl<__T,  __DB, $($ST,)*> Queryable<Nullable<($($ST,)*)>, __DB> for Option<__T>
440                where __DB: Backend,
441                      Self: FromStaticSqlRow<Nullable<($($ST,)*)>, __DB>,
442                ($($ST,)*): SqlType,
443                {
444                    type Row = Self;
445
446                    fn build(row: Self::Row) -> deserialize::Result<Self> {
447                        Ok(row)
448                    }
449                }
450            //}
451
452            impl<$($T,)*> TupleSize for ($($T,)*)
453                where $($T: TupleSize,)*
454            {
455                const SIZE: usize = $($T::SIZE +)* 0;
456            }
457
458            impl<$($T,)*> TupleSize for Nullable<($($T,)*)>
459            where $($T: TupleSize,)*
460                  ($($T,)*): SqlType,
461            {
462                const SIZE: usize = $($T::SIZE +)* 0;
463            }
464
465            fake_variadic! {
466                $Tuple ->
467                impl<$($T,)* __DB> QueryMetadata<($($T,)*)> for __DB
468                where __DB: Backend,
469                $(__DB: QueryMetadata<$T>,)*
470                {
471                    fn row_metadata(lookup: &mut Self::MetadataLookup, row: &mut Vec<Option<__DB::TypeMetadata>>) {
472                        $(
473                            <__DB as QueryMetadata<$T>>::row_metadata(lookup, row);
474                        )*
475                    }
476                }
477            }
478
479            // That's unfortunally not supported yet
480            // fake_variadic! {
481            //     $Tuple ->
482                impl<$($T,)* __DB> QueryMetadata<Nullable<($($T,)*)>> for __DB
483                where __DB: Backend,
484                $(__DB: QueryMetadata<$T>,)*
485                {
486                    fn row_metadata(lookup: &mut Self::MetadataLookup, row: &mut Vec<Option<__DB::TypeMetadata>>) {
487                        $(
488                            <__DB as QueryMetadata<$T>>::row_metadata(lookup, row);
489                        )*
490                    }
491                }
492            //}
493
494            fake_variadic! {
495                $Tuple ->
496                impl<$($T,)* __DB> deserialize::QueryableByName< __DB> for ($($T,)*)
497                where __DB: Backend,
498                $($T: deserialize::QueryableByName<__DB>,)*
499                {
500                    fn build<'a>(row: &impl NamedRow<'a, __DB>) -> deserialize::Result<Self> {
501                        Ok(($(
502                            <$T as deserialize::QueryableByName<__DB>>::build(row)?,
503                        )*))
504                    }
505                }
506            }
507
508            #[diagnostic::do_not_recommend]
509            impl<__T, $($ST,)* __DB> CompatibleType<__T, __DB> for ($($ST,)*)
510            where
511                __DB: Backend,
512                $($ST: CompatibleTupleElement,)*
513                __T: FromSqlRow<($($ST::SqlType,)*), __DB>,
514            {
515                type SqlType = ($($ST::SqlType,)*);
516            }
517
518            impl<__T, $($ST,)* __DB> CompatibleType<Option<__T>, __DB> for Nullable<($($ST,)*)>
519            where
520                __DB: Backend,
521                ($($ST,)*): CompatibleType<__T, __DB>
522            {
523                type SqlType = Nullable<<($($ST,)*) as CompatibleType<__T, __DB>>::SqlType>;
524            }
525
526            impl<$($ST,)*> SqlTypeLikeMarker for ($($ST,)*)
527            where $($ST: SqlTypeLikeMarker,)*
528            {
529                type SqlType = ($($ST::SqlType,)*);
530            }
531
532            impl<$($ST,)*> SqlTypeLikeMarker for Nullable<($($ST,)*)>
533            where ($($ST,)*): SqlTypeLikeMarker
534            {
535                type SqlType = Nullable<<($($ST,)*) as SqlTypeLikeMarker>::SqlType>;
536            }
537        )+
538    }
539}
540
541macro_rules! impl_from_sql_row {
542    (($T1: ident,), ($ST1: ident,)) => {
543        #[cfg_attr(diesel_docsrs, doc(fake_variadic))]
544        impl<$T1, $ST1, __DB> crate::deserialize::FromStaticSqlRow<($ST1,), __DB> for ($T1,) where
545            __DB: Backend,
546            $ST1: CompatibleType<$T1, __DB>,
547            $T1: FromSqlRow<<$ST1 as CompatibleType<$T1, __DB>>::SqlType, __DB>,
548        {
549
550            #[allow(non_snake_case, unused_variables, unused_mut)]
551            fn build_from_row<'a>(row: &impl Row<'a, __DB>)
552                                                       -> deserialize::Result<Self>
553            {
554                Ok(($T1::build_from_row(row)?,))
555            }
556        }
557    };
558    (($T1: ident, $($T: ident,)*), ($ST1: ident, $($ST: ident,)*)) => {
559        #[cfg_attr(diesel_docsrs, doc(hidden))]
560        #[diagnostic::do_not_recommend]
561        impl<$T1, $($T,)* $($ST,)* __DB> FromSqlRow<($($ST,)* crate::sql_types::Untyped), __DB> for ($($T,)* $T1)
562        where __DB: Backend,
563              $T1: FromSqlRow<crate::sql_types::Untyped, __DB>,
564            $(
565                $T: FromSqlRow<$ST, __DB> + StaticallySizedRow<$ST, __DB>,
566        )*
567        {
568            #[allow(non_snake_case, unused_variables, unused_mut)]
569            fn build_from_row<'a>(full_row: &impl Row<'a, __DB>)
570                -> deserialize::Result<Self>
571            {
572                let field_count = full_row.field_count();
573
574                let mut static_field_count = 0;
575                $(
576                    let row = full_row.partial_row(static_field_count..static_field_count + $T::FIELD_COUNT);
577                    static_field_count += $T::FIELD_COUNT;
578                    let $T = $T::build_from_row(&row)?;
579                )*
580
581                let row = full_row.partial_row(static_field_count..field_count);
582
583                Ok(($($T,)* $T1::build_from_row(&row)?,))
584            }
585        }
586
587        #[cfg_attr(diesel_docsrs, doc(hidden))]
588        impl<$T1, $ST1, $($T,)* $($ST,)* __DB> FromStaticSqlRow<($($ST,)* $ST1,), __DB> for ($($T,)* $T1,) where
589            __DB: Backend,
590            $ST1: CompatibleType<$T1, __DB>,
591            $T1: FromSqlRow<<$ST1 as CompatibleType<$T1, __DB>>::SqlType, __DB>,
592            $(
593                $ST: CompatibleType<$T, __DB>,
594                $T: FromSqlRow<<$ST as CompatibleType<$T, __DB>>::SqlType, __DB> + StaticallySizedRow<<$ST as CompatibleType<$T, __DB>>::SqlType, __DB>,
595            )*
596
597        {
598
599            #[allow(non_snake_case, unused_variables, unused_mut)]
600            fn build_from_row<'a>(full_row: &impl Row<'a, __DB>)
601                -> deserialize::Result<Self>
602            {
603                let field_count = full_row.field_count();
604
605                let mut static_field_count = 0;
606                $(
607                    let row = full_row.partial_row(static_field_count..static_field_count + $T::FIELD_COUNT);
608                    static_field_count += $T::FIELD_COUNT;
609                    let $T = <$T as FromSqlRow<<$ST as CompatibleType<$T, __DB>>::SqlType, __DB>>::build_from_row(&row)?;
610                )*
611
612                let row = full_row.partial_row(static_field_count..field_count);
613
614                Ok(($($T,)* $T1::build_from_row(&row)?,))
615            }
616        }
617    }
618}
619
620macro_rules! impl_valid_grouping_for_tuple_of_columns {
621    ($T1: ident, $($T: ident,)+) => {
622        #[cfg_attr(diesel_docsrs, doc(hidden))]
623        impl<$T1, $($T,)* __GroupByClause> ValidGrouping<__GroupByClause> for ($T1, $($T,)*)
624        where
625            $T1: ValidGrouping<__GroupByClause>,
626            ($($T,)*): ValidGrouping<__GroupByClause>,
627            $T1::IsAggregate: MixedAggregates<<($($T,)*) as ValidGrouping<__GroupByClause>>::IsAggregate>,
628        {
629            type IsAggregate = <$T1::IsAggregate as MixedAggregates<<($($T,)*) as ValidGrouping<__GroupByClause>>::IsAggregate>>::Output;
630        }
631
632        impl<$T1, $($T,)* Col> IsContainedInGroupBy<Col> for ($T1, $($T,)*)
633        where Col: QueryRelationField,
634              ($($T,)*): IsContainedInGroupBy<Col>,
635              $T1: IsContainedInGroupBy<Col>,
636              $T1::Output: is_contained_in_group_by::IsAny<<($($T,)*) as IsContainedInGroupBy<Col>>::Output>
637        {
638            type Output = <$T1::Output as is_contained_in_group_by::IsAny<<($($T,)*) as IsContainedInGroupBy<Col>>::Output>>::Output;
639        }
640    };
641    ($T1: ident,) => {
642        impl<$T1, Col> IsContainedInGroupBy<Col> for ($T1,)
643        where Col: QueryRelationField,
644              $T1: IsContainedInGroupBy<Col>
645        {
646            type Output = <$T1 as IsContainedInGroupBy<Col>>::Output;
647        }
648
649        #[cfg_attr(diesel_docsrs, doc(fake_variadic))]
650        impl<$T1, __GroupByClause> ValidGrouping<__GroupByClause> for ($T1,)
651            where $T1: ValidGrouping<__GroupByClause>
652        {
653            type IsAggregate = $T1::IsAggregate;
654        }
655    };
656}
657
658macro_rules! impl_sql_type {
659    (
660        @build
661        start_ts = [$($ST: ident,)*],
662        ts = [$T1: ident,],
663        bounds = [$($bounds: tt)*],
664        is_null = [$($is_null: tt)*],
665    )=> {
666        #[cfg_attr(diesel_docsrs, doc(hidden))]
667        impl<$($ST,)*> SqlType for ($($ST,)*)
668        where
669            $($ST: SqlType,)*
670            $($bounds)*
671            $T1::IsNull: OneIsNullable<$($is_null)*>,
672        {
673            type IsNull = <$T1::IsNull as OneIsNullable<$($is_null)*>>::Out;
674        }
675
676    };
677    (
678        @build
679        start_ts = [$($ST: ident,)*],
680        ts = [$T1: ident, $($T: ident,)+],
681        bounds = [$($bounds: tt)*],
682        is_null = [$($is_null: tt)*],
683    )=> {
684        impl_sql_type!{
685            @build
686            start_ts = [$($ST,)*],
687            ts = [$($T,)*],
688            bounds = [$($bounds)* $T1::IsNull: OneIsNullable<$($is_null)*>,],
689            is_null = [<$T1::IsNull as OneIsNullable<$($is_null)*>>::Out],
690        }
691    };
692    ($T1: ident, $($T: ident,)+) => {
693        impl_sql_type!{
694            @build
695            start_ts = [$T1, $($T,)*],
696            ts = [$($T,)*],
697            bounds = [],
698            is_null = [$T1::IsNull],
699        }
700    };
701    ($T1: ident,) => {
702        #[cfg_attr(diesel_docsrs, doc(fake_variadic))]
703        impl<$T1> SqlType for ($T1,)
704        where $T1: SqlType,
705        {
706            type IsNull = $T1::IsNull;
707        }
708    }
709}
710
711crate::for_each_tuple!(tuple_impls);