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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use std::rc::Rc;
use std::fmt::Write;
use crate::{query::*, expr::*};
pub trait Iden {
fn prepare(&self, s: &mut dyn Write, q: char) {
write!(s, "{}", q).unwrap();
self.unquoted(s);
write!(s, "{}", q).unwrap();
}
fn to_string(&self) -> String {
let s = &mut String::new();
self.unquoted(s);
s.to_owned()
}
fn unquoted(&self, s: &mut dyn Write);
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone)]
pub enum TableRef {
Table(Rc<dyn Iden>),
TableAlias(Rc<dyn Iden>, Rc<dyn Iden>),
SubQuery(SelectStatement, Rc<dyn Iden>),
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum UnOper {
Not,
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum BinOper {
And,
Or,
Like,
NotLike,
Is,
IsNot,
In,
NotIn,
Between,
NotBetween,
Equal,
NotEqual,
SmallerThan,
GreaterThan,
SmallerThanOrEqual,
GreaterThanOrEqual,
Add,
Sub,
Mul,
Div,
}
#[derive(Clone)]
pub enum LogicalChainOper {
And(SimpleExpr),
Or(SimpleExpr),
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum JoinType {
Join,
InnerJoin,
LeftJoin,
RightJoin,
}
#[derive(Clone)]
pub struct OrderExpr {
pub(crate) expr: SimpleExpr,
pub(crate) order: Order,
}
#[derive(Clone)]
pub enum JoinOn {
Condition(Box<SimpleExpr>),
Columns(Vec<SimpleExpr>),
}
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Order {
Asc,
Desc,
}
#[derive(Clone)]
pub struct Alias(String);
impl Alias {
pub fn new(n: &str) -> Self {
Self(n.to_owned())
}
}
impl Iden for Alias {
fn unquoted(&self, s: &mut dyn Write) {
write!(s, "{}", self.0).unwrap();
}
}