|
@@ -148,6 +148,27 @@ where
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#[derive(Debug)]
|
|
|
+pub enum CompareOp {
|
|
|
+ LessThan,
|
|
|
+ AtMost,
|
|
|
+ Equals,
|
|
|
+ AtLeast,
|
|
|
+ MoreThan,
|
|
|
+}
|
|
|
+
|
|
|
+impl CompareOp {
|
|
|
+ fn ch(&self) -> &'static str {
|
|
|
+ match self {
|
|
|
+ Self::LessThan => "<",
|
|
|
+ Self::AtMost => "<=",
|
|
|
+ Self::Equals => "=",
|
|
|
+ Self::AtLeast => ">=",
|
|
|
+ Self::MoreThan => ">",
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// Any query that can have a WHERE clause attached to it
|
|
|
pub trait Filterable<'r, 'q>: Resolvable<'r, 'q, Self::Table>
|
|
|
where
|
|
@@ -166,6 +187,25 @@ where
|
|
|
Filter {
|
|
|
wrap: self,
|
|
|
col,
|
|
|
+ op: CompareOp::Equals,
|
|
|
+ given,
|
|
|
+ _ghost: PhantomData,
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fn by_op<C: EntityColumn<Entity = Self::Table>, G: Modelable + ?Sized>(
|
|
|
+ self,
|
|
|
+ col: C,
|
|
|
+ op: CompareOp,
|
|
|
+ given: &'r G
|
|
|
+ ) -> Filter<'r, 'q, Self, C, G>
|
|
|
+ where
|
|
|
+ Self: Sized,
|
|
|
+ {
|
|
|
+ Filter {
|
|
|
+ wrap: self,
|
|
|
+ col,
|
|
|
+ op,
|
|
|
given,
|
|
|
_ghost: PhantomData,
|
|
|
}
|
|
@@ -270,6 +310,7 @@ where
|
|
|
{
|
|
|
wrap: F,
|
|
|
col: C,
|
|
|
+ op: CompareOp,
|
|
|
given: &'r G,
|
|
|
_ghost: PhantomData<&'q ()>,
|
|
|
}
|
|
@@ -291,7 +332,7 @@ where
|
|
|
fn derive(&self) -> DerivedQuery {
|
|
|
self.wrap
|
|
|
.derive()
|
|
|
- .add(QueryPart::Where, format!("{} = ?", self.col.name()))
|
|
|
+ .add(QueryPart::Where, format!("{} {} ?", self.col.name(), self.op.ch()))
|
|
|
}
|
|
|
|
|
|
fn contribute<H: Hasher>(&self, hasher: &mut H) {
|