teo_sql_connector/exts/
sort.rs1use teo_runtime::sort::Sort;
2
3pub trait SortExt {
4
5 fn from_desc_bool(desc: bool) -> Sort;
6
7 fn from_mysql_str(s: &str) -> Option<Sort>;
8
9 fn from_str(s: &str) -> Option<Sort>;
10
11 fn to_str(&self) -> &'static str;
12}
13
14impl SortExt for Sort {
15
16 fn from_desc_bool(desc: bool) -> Sort {
17 match desc {
18 true => Sort::Desc,
19 false => Sort::Asc,
20 }
21 }
22
23 fn from_mysql_str(s: &str) -> Option<Sort> {
24 match s {
25 "A" => Some(Sort::Asc),
26 "D" => Some(Sort::Desc),
27 _ => None,
28 }
29 }
30
31 fn from_str(s: &str) -> Option<Sort> {
32 match s {
33 "ASC" => Some(Sort::Asc),
34 "DESC" => Some(Sort::Desc),
35 _ => None,
36 }
37 }
38
39 fn to_str(&self) -> &'static str {
40 match self {
41 Sort::Asc => "ASC",
42 Sort::Desc => "DESC",
43 }
44 }
45}