Skip to main content

schema_sql_generator/common/
output_mode.rs

1use std::str::FromStr;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum OutputMode {
5    All,
6    IndexesOnly,
7    TriggersOnly,
8}
9
10impl OutputMode {
11    pub fn includes_indexes(self) -> bool {
12        matches!(self, OutputMode::All | OutputMode::IndexesOnly)
13    }
14    pub fn includes_triggers(self) -> bool {
15        matches!(self, OutputMode::All | OutputMode::TriggersOnly)
16    }
17    pub fn includes_tables(self) -> bool {
18        matches!(self, OutputMode::All)
19    }
20    pub fn includes_views(self) -> bool { matches!(self, OutputMode::All) }
21    pub fn includes_routines(self) -> bool { matches!(self, OutputMode::All) }
22    pub fn includes_other_sql(self) -> bool { matches!(self, OutputMode::All) }
23}
24
25impl FromStr for OutputMode {
26    type Err = String;
27
28    fn from_str(s: &str) -> Result<Self, Self::Err> {
29        match s.to_lowercase().as_str() {
30            "all" => Ok(OutputMode::All),
31            "indexes-only" => Ok(OutputMode::IndexesOnly),
32            "triggers-only" => Ok(OutputMode::TriggersOnly),
33            _ => Err(format!("Unknown output mode: {}", s)),
34        }
35    }
36}