use crate::prelude::*;
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug)]
pub struct Column {
name: String,
alias: Option<String>,
}
impl Column {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
alias: None,
}
}
pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
self.alias = Some(alias.into());
self
}
}
impl Sql for Column {
fn sql(&self, mut s: String, _ctx: &Context) -> Result<String> {
s.push_str(&self.name);
if let Some(alias) = &self.alias {
s.push_str(" AS ");
s.push_str(alias)
}
Ok(s)
}
}
impl From<&str> for Column {
fn from(value: &str) -> Self {
Column::new(value)
}
}