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::Table;
7
8pub trait CombineDsl {
11 type Query: Query;
13
14 fn union<Rhs>(self, rhs: Rhs) -> dsl::Union<Self, Rhs>
46 where
47 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
48
49 fn union_all<Rhs>(self, rhs: Rhs) -> dsl::UnionAll<Self, Rhs>
51 where
52 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
53
54 fn intersect<Rhs>(self, rhs: Rhs) -> dsl::Intersect<Self, Rhs>
56 where
57 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
58
59 fn intersect_all<Rhs>(self, rhs: Rhs) -> dsl::IntersectAll<Self, Rhs>
61 where
62 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
63
64 fn except<Rhs>(self, rhs: Rhs) -> dsl::Except<Self, Rhs>
66 where
67 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
68
69 fn except_all<Rhs>(self, rhs: Rhs) -> dsl::ExceptAll<Self, Rhs>
71 where
72 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>;
73}
74
75impl<T: Table> CombineDsl for T {
76 type Query = T::Query;
77
78 fn union<Rhs>(self, rhs: Rhs) -> dsl::Union<Self, Rhs>
79 where
80 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
81 {
82 CombinationClause::new(Union, Distinct, self.as_query(), rhs.as_query())
83 }
84
85 fn union_all<Rhs>(self, rhs: Rhs) -> dsl::UnionAll<Self, Rhs>
86 where
87 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
88 {
89 CombinationClause::new(Union, All, self.as_query(), rhs.as_query())
90 }
91
92 fn intersect<Rhs>(self, rhs: Rhs) -> dsl::Intersect<Self, Rhs>
93 where
94 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
95 {
96 CombinationClause::new(Intersect, Distinct, self.as_query(), rhs.as_query())
97 }
98
99 fn intersect_all<Rhs>(self, rhs: Rhs) -> dsl::IntersectAll<Self, Rhs>
100 where
101 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
102 {
103 CombinationClause::new(Intersect, All, self.as_query(), rhs.as_query())
104 }
105
106 fn except<Rhs>(self, rhs: Rhs) -> dsl::Except<Self, Rhs>
107 where
108 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
109 {
110 CombinationClause::new(Except, Distinct, self.as_query(), rhs.as_query())
111 }
112
113 fn except_all<Rhs>(self, rhs: Rhs) -> dsl::ExceptAll<Self, Rhs>
114 where
115 Rhs: AsQuery<SqlType = <Self::Query as Query>::SqlType>,
116 {
117 CombinationClause::new(Except, All, self.as_query(), rhs.as_query())
118 }
119}