diesel/query_dsl/
filter_dsl.rs1use crate::dsl::{Filter, OrFilter};
2use crate::expression_methods::*;
3use crate::query_source::*;
4
5pub trait FilterDsl<Predicate> {
13 type Output;
15
16 fn filter(self, predicate: Predicate) -> Self::Output;
18}
19
20impl<T, Predicate> FilterDsl<Predicate> for T
21where
22 T: Table,
23 T::Query: FilterDsl<Predicate>,
24{
25 type Output = Filter<T::Query, Predicate>;
26
27 fn filter(self, predicate: Predicate) -> Self::Output {
28 self.as_query().filter(predicate)
29 }
30}
31
32pub trait FindDsl<PK> {
40 type Output;
42
43 fn find(self, id: PK) -> Self::Output;
45}
46
47impl<T, PK> FindDsl<PK> for T
48where
49 T: Table + FilterDsl<<<T as Table>::PrimaryKey as EqAll<PK>>::Output>,
50 T::PrimaryKey: EqAll<PK>,
51{
52 type Output = Filter<Self, <T::PrimaryKey as EqAll<PK>>::Output>;
53
54 fn find(self, id: PK) -> Self::Output {
55 let primary_key = self.primary_key();
56 self.filter(primary_key.eq_all(id))
57 }
58}
59
60pub trait OrFilterDsl<Predicate> {
68 type Output;
70
71 fn or_filter(self, predicate: Predicate) -> Self::Output;
73}
74
75impl<T, Predicate> OrFilterDsl<Predicate> for T
76where
77 T: Table,
78 T::Query: OrFilterDsl<Predicate>,
79{
80 type Output = OrFilter<T::Query, Predicate>;
81
82 fn or_filter(self, predicate: Predicate) -> Self::Output {
83 self.as_query().or_filter(predicate)
84 }
85}