use std::borrow::Cow;
pub(crate) fn build_column_alias(table: &str, name: &str) -> String {
let mut alias = String::with_capacity(table.len() + name.len() + 2);
alias.push_str(table);
alias.push_str("__");
alias.push_str(name);
alias
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColumnMarker {
pub table: Cow<'static, str>,
pub name: Cow<'static, str>,
}
impl ColumnMarker {
pub fn new(table: impl Into<String>, name: impl Into<String>) -> Self {
Self {
table: Cow::Owned(table.into()),
name: Cow::Owned(name.into()),
}
}
pub const fn from_static(table: &'static str, name: &'static str) -> Self {
Self {
table: Cow::Borrowed(table),
name: Cow::Borrowed(name),
}
}
pub fn alias(&self) -> String {
build_column_alias(&self.table, &self.name)
}
}