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
use crate::{
    ast::ColumnDef,
    parse_sql::parse_column_def,
    result::{Error, Result},
    translate::translate_column_def,
};

#[derive(Clone, Debug)]
pub enum ColumnDefNode {
    Text(String),
}

impl From<&str> for ColumnDefNode {
    fn from(column_def: &str) -> Self {
        ColumnDefNode::Text(column_def.to_owned())
    }
}

impl TryFrom<ColumnDefNode> for ColumnDef {
    type Error = Error;

    fn try_from(column_def_node: ColumnDefNode) -> Result<ColumnDef> {
        match column_def_node {
            ColumnDefNode::Text(column_def) => parse_column_def(column_def)
                .and_then(|column_def| translate_column_def(&column_def)),
        }
    }
}