#[must_use]
pub fn same_name(left: &str, right: &str) -> bool {
left.eq_ignore_ascii_case(right)
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QualifiedName {
pub catalog: String,
pub schema: String,
pub table: String,
}
impl QualifiedName {
pub fn new(
catalog: impl Into<String>,
schema: impl Into<String>,
table: impl Into<String>,
) -> Self {
Self { catalog: catalog.into(), schema: schema.into(), table: table.into() }
}
#[must_use]
pub fn same_as(&self, other: &Self) -> bool {
same_name(&self.catalog, &other.catalog)
&& same_name(&self.schema, &other.schema)
&& same_name(&self.table, &other.table)
}
}
impl std::fmt::Display for QualifiedName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}", self.catalog, self.schema, self.table)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_name_matches_whatever_case_it_was_written_in() {
assert!(same_name("MyTable", "mytable"));
assert!(same_name("HITS", "hits"));
assert!(!same_name("hits", "hit"));
}
#[test]
fn matching_a_name_does_not_change_it() {
let name = QualifiedName::new("memory", "main", "MyTable");
assert!(name.same_as(&QualifiedName::new("MEMORY", "Main", "mytable")));
assert_eq!(name.to_string(), "memory.main.MyTable");
}
}