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
/// Provides a standard implementation of `QueryId`.
/// Apps should not need to concern themselves with this macro.
///
/// This macro should be called with the name of your type, along with all of
/// it's type parameters.
/// If the SQL generated by your type not uniquely identifiable by the type
/// itself, you should put `noop:` in front.
///
/// For example, given the type `And<Left, Right>`, invoking
/// `impl_query_id!(And<Left, Right>)` will generate:
///
/// ```rust,ignore
/// impl<Left, Right> QueryId for And<Left, Right>
/// where
///     Left: QueryId,
///     Right: QueryId,
/// {
///     type QueryId = And<Left::QueryId, Right::QueryId>;
///
///     const HAS_STATIC_QUERY_ID: bool = Left::HAS_STATIC_QUERY_ID && Right::HAS_STATIC_QUERY_ID;
/// }
/// ```
///
/// Invoking `impl_query_id!(noop: And<Left, Right>)` will generate:
///
/// ```rust,ignore
/// impl<Left, Right> QueryId for And<Left, Right> {
///     type QueryId = ();
///
///     const HAS_STATIC_QUERY_ID: bool = false;
/// }
/// ```
#[macro_export]
#[cfg(feature = "with-deprecated")]
#[deprecated(since = "1.1.0", note = "Use `#[derive(QueryId)]` instead")]
macro_rules! impl_query_id {
    ($name: ident) => {
        impl $crate::query_builder::QueryId for $name {
            type QueryId = Self;

            const HAS_STATIC_QUERY_ID: bool = true;
        }
    };

    ($name: ident<$($ty_param: ident),+>) => {
        #[allow(non_camel_case_types)]
        impl<$($ty_param),*> $crate::query_builder::QueryId for $name<$($ty_param),*> where
            $($ty_param: $crate::query_builder::QueryId),*
        {
            type QueryId = $name<$($ty_param::QueryId),*>;

            const HAS_STATIC_QUERY_ID: bool = $($ty_param::HAS_STATIC_QUERY_ID &&)* true;
        }
    };

    (noop: $name: ident) => {
        impl $crate::query_builder::QueryId for $name {
            type QueryId = ();

            const HAS_STATIC_QUERY_ID: bool = false;
        }
    };

    (noop: $name: ident<$($ty_param: ident),+>) => {
        #[allow(non_camel_case_types)]
        impl<$($ty_param),*> $crate::query_builder::QueryId for $name<$($ty_param),*> {
            type QueryId = ();

            const HAS_STATIC_QUERY_ID: bool = false;
        }
    }
}