Skip to main content

no_mistakes_postgres_sql/function_calls/
clause.rs

1/// The innermost SQL clause containing a syntactic function call.
2#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3pub enum SqlFunctionClause {
4    Where,
5    JoinOn,
6    Having,
7    SelectList,
8    OrderBy,
9    Values,
10    Set,
11    Default,
12    Returning,
13}
14
15impl SqlFunctionClause {
16    pub fn parse(value: &str) -> Option<Self> {
17        Some(match value {
18            "where" => Self::Where,
19            "join-on" => Self::JoinOn,
20            "having" => Self::Having,
21            "select-list" => Self::SelectList,
22            "order-by" => Self::OrderBy,
23            "values" => Self::Values,
24            "set" => Self::Set,
25            "default" => Self::Default,
26            "returning" => Self::Returning,
27            _ => return None,
28        })
29    }
30
31    pub fn as_str(self) -> &'static str {
32        match self {
33            Self::Where => "where",
34            Self::JoinOn => "join-on",
35            Self::Having => "having",
36            Self::SelectList => "select-list",
37            Self::OrderBy => "order-by",
38            Self::Values => "values",
39            Self::Set => "set",
40            Self::Default => "default",
41            Self::Returning => "returning",
42        }
43    }
44
45    pub fn label(self) -> &'static str {
46        match self {
47            Self::Where => "WHERE",
48            Self::JoinOn => "JOIN ON",
49            Self::Having => "HAVING",
50            Self::SelectList => "SELECT list",
51            Self::OrderBy => "ORDER BY",
52            Self::Values => "VALUES",
53            Self::Set => "SET",
54            Self::Default => "DEFAULT",
55            Self::Returning => "RETURNING",
56        }
57    }
58}