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
use crate::component::datatype::DataType;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Field {
pub name: String,
pub datatype: DataType,
pub not_null: bool,
pub default: Option<String>,
pub check: Checker,
pub encrypt: bool,
uuid: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Checker {
None,
Some(Operator, String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Operator {
LT,
LE,
EQ,
NE,
GT,
GE,
}
impl Field {
pub fn new(name: &str, datatype: DataType) -> Field {
Field {
name: name.to_string(),
datatype,
not_null: false,
default: None,
check: Checker::None,
encrypt: false,
uuid: Uuid::new_v4().to_string(),
}
}
#[allow(dead_code)]
pub fn new_all(
name: &str,
datatype: DataType,
not_null: bool,
default: Option<String>,
check: Checker,
encrypt: bool,
) -> Field {
Field {
name: name.to_string(),
datatype,
not_null,
default,
check,
encrypt,
uuid: Uuid::new_v4().to_string(),
}
}
}