diesel/macros/query_id.rs
1/// Provides a standard implementation of `QueryId`.
2/// Apps should not need to concern themselves with this macro.
3///
4/// This macro should be called with the name of your type, along with all of
5/// it's type parameters.
6/// If the SQL generated by your type not uniquely identifiable by the type
7/// itself, you should put `noop:` in front.
8///
9/// For example, given the type `And<Left, Right>`, invoking
10/// `impl_query_id!(And<Left, Right>)` will generate:
11///
12/// ```rust,ignore
13/// impl<Left, Right> QueryId for And<Left, Right>
14/// where
15/// Left: QueryId,
16/// Right: QueryId,
17/// {
18/// type QueryId = And<Left::QueryId, Right::QueryId>;
19///
20/// const HAS_STATIC_QUERY_ID: bool = Left::HAS_STATIC_QUERY_ID && Right::HAS_STATIC_QUERY_ID;
21/// }
22/// ```
23///
24/// Invoking `impl_query_id!(noop: And<Left, Right>)` will generate:
25///
26/// ```rust,ignore
27/// impl<Left, Right> QueryId for And<Left, Right> {
28/// type QueryId = ();
29///
30/// const HAS_STATIC_QUERY_ID: bool = false;
31/// }
32/// ```
33#[macro_export]
34#[cfg(feature = "with-deprecated")]
35#[deprecated(since = "1.1.0", note = "Use `#[derive(QueryId)]` instead")]
36macro_rules! impl_query_id {
37 ($name: ident) => {
38 impl $crate::query_builder::QueryId for $name {
39 type QueryId = Self;
40
41 const HAS_STATIC_QUERY_ID: bool = true;
42 }
43 };
44
45 ($name: ident<$($ty_param: ident),+>) => {
46 #[allow(non_camel_case_types)]
47 impl<$($ty_param),*> $crate::query_builder::QueryId for $name<$($ty_param),*> where
48 $($ty_param: $crate::query_builder::QueryId),*
49 {
50 type QueryId = $name<$($ty_param::QueryId),*>;
51
52 const HAS_STATIC_QUERY_ID: bool = $($ty_param::HAS_STATIC_QUERY_ID &&)* true;
53 }
54 };
55
56 (noop: $name: ident) => {
57 impl $crate::query_builder::QueryId for $name {
58 type QueryId = ();
59
60 const HAS_STATIC_QUERY_ID: bool = false;
61 }
62 };
63
64 (noop: $name: ident<$($ty_param: ident),+>) => {
65 #[allow(non_camel_case_types)]
66 impl<$($ty_param),*> $crate::query_builder::QueryId for $name<$($ty_param),*> {
67 type QueryId = ();
68
69 const HAS_STATIC_QUERY_ID: bool = false;
70 }
71 }
72}