1use crate::prelude::*;
2
3#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
4#[derive(Debug)]
5pub struct Column {
6 name: String,
7 alias: Option<String>,
8}
9
10impl Column {
11 pub fn new(name: impl Into<String>) -> Self {
12 Self {
13 name: name.into(),
14 alias: None,
15 }
16 }
17
18 pub fn with_alias(mut self, alias: impl Into<String>) -> Self {
19 self.alias = Some(alias.into());
20 self
21 }
22}
23
24impl Sql for Column {
25 fn sql(&self, mut s: String, _ctx: &Context) -> Result<String> {
26 s.push_str(&self.name);
27
28 if let Some(alias) = &self.alias {
29 s.push_str(" AS ");
30 s.push_str(alias)
31 }
32
33 Ok(s)
34 }
35}
36
37impl From<&str> for Column {
38 fn from(value: &str) -> Self {
39 Column::new(value)
40 }
41}