diesel/query_dsl/
combine_dsl.rs1use crate::dsl;
2use crate::query_builder::combination_clause::{
3 All, CombinationClause, Distinct, Except, Intersect, Union,
4};
5use crate::query_builder::{AsQuery, Query};
6use crate::query_source::QueryRelation;
7
8pub trait CombineDsl {
11 type Query: Query;
13
14 fn union<Rhs>(self, rhs: Rhs) -> dsl::Union<Self, Rhs>
51 where
52 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
53
54 fn union_all<Rhs>(self, rhs: Rhs) -> dsl::UnionAll<Self, Rhs>
56 where
57 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
58
59 fn intersect<Rhs>(self, rhs: Rhs) -> dsl::Intersect<Self, Rhs>
61 where
62 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
63
64 fn intersect_all<Rhs>(self, rhs: Rhs) -> dsl::IntersectAll<Self, Rhs>
66 where
67 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
68
69 fn except<Rhs>(self, rhs: Rhs) -> dsl::Except<Self, Rhs>
71 where
72 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
73
74 fn except_all<Rhs>(self, rhs: Rhs) -> dsl::ExceptAll<Self, Rhs>
76 where
77 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
78}
79
80impl<T: QueryRelation> CombineDsl for T {
81 type Query = T::Query;
82
83 fn union<Rhs>(self, rhs: Rhs) -> dsl::Union<Self, Rhs>
84 where
85 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
86 {
87 CombinationClause::new(Union, Distinct, self.as_query(), rhs.as_query())
88 }
89
90 fn union_all<Rhs>(self, rhs: Rhs) -> dsl::UnionAll<Self, Rhs>
91 where
92 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
93 {
94 CombinationClause::new(Union, All, self.as_query(), rhs.as_query())
95 }
96
97 fn intersect<Rhs>(self, rhs: Rhs) -> dsl::Intersect<Self, Rhs>
98 where
99 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
100 {
101 CombinationClause::new(Intersect, Distinct, self.as_query(), rhs.as_query())
102 }
103
104 fn intersect_all<Rhs>(self, rhs: Rhs) -> dsl::IntersectAll<Self, Rhs>
105 where
106 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
107 {
108 CombinationClause::new(Intersect, All, self.as_query(), rhs.as_query())
109 }
110
111 fn except<Rhs>(self, rhs: Rhs) -> dsl::Except<Self, Rhs>
112 where
113 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
114 {
115 CombinationClause::new(Except, Distinct, self.as_query(), rhs.as_query())
116 }
117
118 fn except_all<Rhs>(self, rhs: Rhs) -> dsl::ExceptAll<Self, Rhs>
119 where
120 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
121 {
122 CombinationClause::new(Except, All, self.as_query(), rhs.as_query())
123 }
124}