Skip to main content

drizzle_core/expr/
subquery.rs

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