use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Location {
pub row: usize,
pub col_start: usize,
pub col_end: usize,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct QualifiedName {
pub schema: Option<String>,
pub name: String,
}
impl fmt::Display for QualifiedName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.schema {
Some(s) => write!(f, "{}.{}", s, self.name),
None => write!(f, "{}", self.name),
}
}
}
#[derive(Debug, Clone)]
pub struct TableReference {
pub qualified_name: QualifiedName,
pub alias: Option<String>,
pub location: Location,
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ColumnReference {
pub table_qualifier: Option<String>,
pub name: String,
pub location: Location,
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ResolvedColumn {
pub name: String,
pub data_type: String,
pub nullable: bool,
pub is_primary_key: bool,
pub table_schema: String,
pub table_name: String,
}
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct ForeignKey {
pub constraint_name: String,
pub from_schema: String,
pub from_table: String,
pub from_columns: Vec<String>,
pub to_schema: String,
pub to_table: String,
pub to_columns: Vec<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn qualified_name_display() {
let unqualified = QualifiedName {
schema: None,
name: "employees".to_string(),
};
assert_eq!(unqualified.to_string(), "employees");
let qualified = QualifiedName {
schema: Some("hr".to_string()),
name: "employees".to_string(),
};
assert_eq!(qualified.to_string(), "hr.employees");
}
}