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