Skip to main content

cartel_sqlite/dsl/query/
join.rs

1use crate::dsl::{query, scope::never::Never};
2
3pub struct Plan2<A, B>(Never<(A, B)>);
4pub struct Plan3<A, B, C>(Never<(A, B, C)>);
5pub struct Plan4<A, B, C, D>(Never<(A, B, C, D)>);
6
7pub struct Rows2<A, B>(Never<(A, B)>);
8pub struct Rows3<A, B, C>(Never<(A, B, C)>);
9pub struct Rows4<A, B, C, D>(Never<(A, B, C, D)>);
10
11impl<A, B> Plan2<A, B> {
12    pub fn filter(self, pred: impl FnOnce(A, B) -> bool) -> Rows2<A, B> {
13        self.0.infer(pred)
14    }
15
16    pub fn join<C>(self, pred: impl FnOnce(A, B, C) -> bool) -> Plan3<A, B, C> {
17        self.0.infer(pred)
18    }
19}
20
21impl<A, B, C> Plan3<A, B, C> {
22    pub fn filter(self, pred: impl FnOnce(A, B, C) -> bool) -> Rows3<A, B, C> {
23        self.0.infer(pred)
24    }
25
26    pub fn join<D>(self, pred: impl FnOnce(A, B, C, D) -> bool) -> Plan4<A, B, C, D> {
27        self.0.infer(pred)
28    }
29}
30
31impl<A, B, C, D> Plan4<A, B, C, D> {
32    pub fn filter(self, pred: impl FnOnce(A, B, C, D) -> bool) -> Rows4<A, B, C, D> {
33        self.0.infer(pred)
34    }
35}
36
37impl<A, B> Rows2<A, B> {
38    pub fn all<R>(self) -> Vec<R> {
39        self.0.infer(())
40    }
41
42    pub fn count(self) -> i64 {
43        self.0.infer(())
44    }
45
46    pub fn order_by<F, U>(self, key: F) -> Self
47    where
48        F: FnOnce(A, B) -> U,
49    {
50        self.0.infer(key)
51    }
52
53    pub fn select<F, R>(self, map: F) -> query::Select<R>
54    where
55        F: FnOnce(A, B) -> R,
56    {
57        self.0.infer(map)
58    }
59}
60
61impl<A, B, C> Rows3<A, B, C> {
62    pub fn all<R>(self) -> Vec<R> {
63        self.0.infer(())
64    }
65
66    pub fn order_by<F, U>(self, key: F) -> Self
67    where
68        F: FnOnce(A, B, C) -> U,
69    {
70        self.0.infer(key)
71    }
72}
73
74impl<A, B, C, D> Rows4<A, B, C, D> {
75    pub fn all<R>(self) -> Vec<R> {
76        self.0.infer(())
77    }
78
79    pub fn order_by<F, U>(self, key: F) -> Self
80    where
81        F: FnOnce(A, B, C, D) -> U,
82    {
83        self.0.infer(key)
84    }
85}