Skip to main content

drizzle_core/expr/
subquery.rs

1//! The SQL type a subquery produces, for use in comparisons and `IN`.
2//!
3//! A one-column select has that column's SQL type; a select of several
4//! columns has a tuple of their SQL types.
5
6use crate::traits::SQLParam;
7use crate::types::DataType;
8
9use super::Expr;
10
11/// Maps a select marker (the type-level record of what a query selects) to
12/// the SQL type the query produces as a subquery.
13pub trait SubqueryType<'a, V: SQLParam> {
14    /// SQL type of the subquery: the column's type, or a tuple of types.
15    type SQLType: DataType;
16}
17
18impl<'a, V, E> SubqueryType<'a, V> for crate::row::SelectCols<(E,)>
19where
20    V: SQLParam + 'a,
21    E: Expr<'a, V>,
22{
23    type SQLType = E::SQLType;
24}
25
26macro_rules! impl_subquery_type_tuple {
27    ($($E:ident),+; $($idx:tt),+) => {
28        impl<'a, V, $($E),+> SubqueryType<'a, V> for crate::row::SelectCols<($($E,)+)>
29        where
30            V: SQLParam + 'a,
31            $($E: Expr<'a, V>,)+
32        {
33            type SQLType = ($($E::SQLType,)+);
34        }
35    };
36}
37
38macro_rules! with_col_sizes_2_to_8 {
39    ($callback:ident) => {
40        seq_tuples!(@from $callback
41            [E0]
42            [0];
43            (E1,1) (E2,2) (E3,3)
44            (E4,4) (E5,5) (E6,6) (E7,7)
45        );
46    };
47}
48
49with_col_sizes_2_to_8!(impl_subquery_type_tuple);
50
51#[cfg(any(
52    feature = "col16",
53    feature = "col32",
54    feature = "col64",
55    feature = "col128",
56    feature = "col200"
57))]
58with_col_sizes_16!(impl_subquery_type_tuple);
59
60#[cfg(any(
61    feature = "col32",
62    feature = "col64",
63    feature = "col128",
64    feature = "col200"
65))]
66with_col_sizes_32!(impl_subquery_type_tuple);
67
68#[cfg(any(feature = "col64", feature = "col128", feature = "col200"))]
69with_col_sizes_64!(impl_subquery_type_tuple);
70
71#[cfg(any(feature = "col128", feature = "col200"))]
72with_col_sizes_128!(impl_subquery_type_tuple);
73
74#[cfg(feature = "col200")]
75with_col_sizes_200!(impl_subquery_type_tuple);
76
77impl<'a, V, M, Scope, Used> SubqueryType<'a, V> for crate::row::Scoped<M, Scope, Used>
78where
79    V: SQLParam + 'a,
80    M: SubqueryType<'a, V>,
81{
82    type SQLType = M::SQLType;
83}