use super::SqlColumnMetadata;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SqlTableSchemaEvent {
Create {
temporary: bool,
if_not_exists: bool,
columns_complete: bool,
source_order: Vec<usize>,
line: usize,
position_column: usize,
table: String,
relation_key: String,
unqualified_table: String,
columns: Vec<SqlColumnMetadata>,
},
AddColumn {
table_if_exists: bool,
if_not_exists: bool,
source_order: Vec<usize>,
line: usize,
position_column: usize,
table: String,
relation_key: String,
unqualified_table: String,
column: SqlColumnMetadata,
},
Drop {
source_order: Vec<usize>,
line: usize,
position_column: usize,
table: String,
relation_key: String,
unqualified_table: String,
},
}
impl SqlTableSchemaEvent {
pub(crate) fn source_order(&self) -> &[usize] {
match self {
Self::Create { source_order, .. }
| Self::AddColumn { source_order, .. }
| Self::Drop { source_order, .. } => source_order,
}
}
pub(crate) fn line(&self) -> usize {
match self {
Self::Create { line, .. } | Self::AddColumn { line, .. } | Self::Drop { line, .. } => {
*line
}
}
}
pub fn precedes_write(&self, line: usize, column: usize) -> bool {
let event_column = match self {
Self::Create {
position_column, ..
}
| Self::AddColumn {
position_column, ..
}
| Self::Drop {
position_column, ..
} => *position_column,
};
self.line() < line || (self.line() == line && event_column < column)
}
pub(crate) fn line_mut(&mut self) -> &mut usize {
match self {
Self::Create { line, .. } | Self::AddColumn { line, .. } | Self::Drop { line, .. } => {
line
}
}
}
pub(crate) fn source_order_mut(&mut self) -> &mut Vec<usize> {
match self {
Self::Create { source_order, .. }
| Self::AddColumn { source_order, .. }
| Self::Drop { source_order, .. } => source_order,
}
}
}