1mod_def! {
2 pub mod operators;
3}
4
5use crate::mod_def;
6use crate::traits::SqlFilter;
7use sqlx::QueryBuilder;
8
9pub struct Filter<T>(T);
10
11impl<T> Filter<T> {
12 #[inline]
13 pub fn new(filter: T) -> Self {
14 Filter(filter)
15 }
16}
17
18#[allow(clippy::should_implement_trait)]
19impl<'args, T: 'args> Filter<T>
20where
21 T: SqlFilter<'args>,
22{
23 #[inline]
24 pub fn and<U>(self, other: U) -> Filter<And<T, U>>
25 where
26 U: SqlFilter<'args>,
27 {
28 Filter(And {
29 left: self.0,
30 right: other,
31 })
32 }
33
34 #[inline]
35 pub fn or<U>(self, other: U) -> Filter<Or<T, U>>
36 where
37 U: SqlFilter<'args>,
38 {
39 Filter(Or {
40 left: self.0,
41 right: other,
42 })
43 }
44
45 #[inline]
46 pub fn not(self) -> Filter<Not<T>> {
47 Filter(Not::new(self.0))
48 }
49}
50
51impl<'args, T> SqlFilter<'args> for Filter<T>
52where
53 T: SqlFilter<'args>,
54{
55 #[inline]
56 #[cfg(feature = "any")]
57 fn apply_filter(self, builder: &mut QueryBuilder<'args, sqlx::Any>) {
58 self.0.apply_filter(builder);
59 }
60 #[inline]
61 #[cfg(all(
62 feature = "postgres",
63 not(any(feature = "sqlite", feature = "mysql", feature = "any"))
64 ))]
65 fn apply_filter(self, builder: &mut QueryBuilder<'args, sqlx::Postgres>) {
66 self.0.apply_filter(builder);
67 }
68 #[inline]
69 #[cfg(all(
70 feature = "mysql",
71 not(any(feature = "sqlite", feature = "any", feature = "postgres"))
72 ))]
73 fn apply_filter(self, builder: &mut QueryBuilder<'args, sqlx::MySql>) {
74 self.0.apply_filter(builder);
75 }
76 #[inline]
77 #[cfg(all(
78 feature = "sqlite",
79 not(any(feature = "any", feature = "mysql", feature = "postgres"))
80 ))]
81 fn apply_filter(self, builder: &mut QueryBuilder<'args, sqlx::Sqlite>) {
82 self.0.apply_filter(builder);
83 }
84
85 #[inline]
86 fn should_apply_filter(&self) -> bool {
87 self.0.should_apply_filter()
88 }
89}