#[derive(Debug, Clone, PartialEq)]
pub enum IRType {
Bool,
Int8,
Int16,
Int32,
Int64,
Float32,
Float64,
Decimal {
precision: u8,
scale: u8,
},
Char {
length: u32,
},
Varchar {
length: Option<u32>,
},
Text,
Binary {
length: Option<u32>,
},
Blob,
Date,
Time {
with_timezone: bool,
},
Timestamp {
with_timezone: bool,
},
Json,
Uuid,
Bit {
length: u32,
},
Other(String),
}
#[derive(Debug, Clone, PartialEq)]
pub enum IRDefault {
CurrentTimestamp,
Literal(String),
RawExpression(String),
}
#[derive(Debug, Clone)]
pub struct IRColumn {
pub name: String,
pub ir_type: IRType,
pub nullable: bool,
pub default_expr: Option<IRDefault>,
pub is_primary_key: bool,
pub is_auto_increment: bool,
pub comment: Option<String>,
}
#[derive(Debug, Clone)]
pub struct IRTable {
pub name: String,
pub columns: Vec<IRColumn>,
pub primary_keys: Vec<String>,
pub table_options: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ir_type_equality() {
assert_eq!(
IRType::Varchar { length: Some(255) },
IRType::Varchar { length: Some(255) },
);
assert_ne!(
IRType::Varchar { length: Some(255) },
IRType::Varchar { length: None },
);
}
#[test]
fn ir_default_equality() {
assert_eq!(IRDefault::CurrentTimestamp, IRDefault::CurrentTimestamp);
assert_ne!(
IRDefault::Literal("42".into()),
IRDefault::RawExpression("42".into()),
);
}
}