1use crate::query::predicate::{Eq, Gt, Lt, Neq, Op};
2use crate::query::select::order::{Ascending, Descending, Ordered};
3use crate::Table;
4
5use std::marker::PhantomData;
6
7pub struct Field<T, A> {
8 name: &'static str,
9 _table: PhantomData<T>,
10 _type: PhantomData<A>,
11}
12
13impl<T, A> Field<T, A>
14where
15 T: Table,
16{
17 pub fn new(name: &'static str) -> Self {
18 Self {
19 name,
20 _table: PhantomData,
21 _type: PhantomData,
22 }
23 }
24
25 pub fn eq<U>(self, rhs: U) -> Op<T, A, U, Eq> {
26 Op::new(self, rhs)
27 }
28
29 pub fn neq<U>(self, rhs: U) -> Op<T, A, U, Neq> {
30 Op::new(self, rhs)
31 }
32
33 pub fn gt<U>(self, rhs: U) -> Op<T, A, U, Gt> {
34 Op::new(self, rhs)
35 }
36
37 pub fn lt<U>(self, rhs: U) -> Op<T, A, U, Lt> {
38 Op::new(self, rhs)
39 }
40
41 pub fn then<T2>(self, next: T2) -> Then<Self, T2> {
42 Then {
43 head: self,
44 tail: next,
45 }
46 }
47
48 pub fn ascending(self) -> Ordered<T, A, Ascending> {
49 Ordered::new(self)
50 }
51
52 pub fn descending(self) -> Ordered<T, A, Descending> {
53 Ordered::new(self)
54 }
55
56 pub(crate) fn write_field(&self, sql: &mut String) {
57 sql.push_str(T::NAME);
58 sql.push('.');
59 sql.push_str(self.name);
60 }
61}
62
63impl<T, A> Copy for Field<T, A> {}
64
65impl<T, A> Clone for Field<T, A> {
66 fn clone(&self) -> Self {
67 *self
68 }
69}
70
71pub struct Then<H, T> {
72 pub(crate) head: H,
73 pub(crate) tail: T,
74}
75
76impl<H, T> Then<H, T> {
77 pub fn then<T2>(self, next: T2) -> Then<Self, T2> {
78 Then {
79 head: self,
80 tail: next,
81 }
82 }
83}