taitan_orm_parser/template_parser/structs/values/
bool_value.rs

1use std::fmt::Display;
2use nom::branch::alt;
3use nom::combinator::map;
4use nom::IResult;
5use crate::template_parser::structs::bool_value::Bool;
6use crate::{ToSqlSegment};
7use crate::template_parser::structs::values::maybe_value::MaybeValue;
8use crate::template_parser::to_sql::SqlSegment;
9
10#[derive(Debug, Clone, PartialEq)]
11pub enum BoolValue {
12    Value(Bool),
13    Maybe(MaybeValue)
14}
15
16impl BoolValue {
17    pub fn parse(input: &str) -> IResult<&str, BoolValue> {
18        alt((
19            map(Bool::parse, BoolValue::Value),
20            map(MaybeValue::parse, BoolValue::Maybe),
21        ))(input)
22    }
23}
24
25impl From<Bool> for BoolValue {
26    fn from(val: Bool) -> Self {
27        BoolValue::Value(val)
28    }
29}
30
31impl From<MaybeValue> for BoolValue {
32    fn from(val: MaybeValue) -> Self {
33        BoolValue::Maybe(val)
34    }
35}
36
37
38impl ToSqlSegment for BoolValue {
39    fn gen_sql_segment(&self) -> SqlSegment {
40        match self {
41            Self::Value(v)=>SqlSegment::Simple(v.to_string()),
42            Self::Maybe(m)=>m.gen_sql_segment(),
43        }
44    }
45}
46