1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::{Id, Predicate, TypedPredicate};
#[derive(Clone, Debug)]
pub enum Filter {
Id(TypedPredicate<Id>),
Type(TypedPredicate<String>),
Created(TypedPredicate<u64>),
LastUpdated(TypedPredicate<u64>),
Field(String, Predicate),
Edge(String, Box<Filter>),
IntoEdge(String),
}
impl Filter {
pub fn where_id<P: Into<TypedPredicate<Id>>>(p: P) -> Self {
Self::Id(p.into())
}
pub fn where_type<P: Into<TypedPredicate<String>>>(p: P) -> Self {
Self::Type(p.into())
}
pub fn where_created<P: Into<TypedPredicate<u64>>>(p: P) -> Self {
Self::Created(p.into())
}
pub fn where_last_updated<P: Into<TypedPredicate<u64>>>(p: P) -> Self {
Self::LastUpdated(p.into())
}
pub fn where_field<S: Into<String>, P: Into<Predicate>>(name: S, p: P) -> Self {
Self::Field(name.into(), p.into())
}
pub fn where_edge<S: Into<String>, F: Into<Filter>>(name: S, filter: F) -> Self {
Self::Edge(name.into(), Box::new(filter.into()))
}
pub fn where_into_edge<S: Into<String>>(name: S) -> Self {
Self::IntoEdge(name.into())
}
}