use crate::prelude::*;
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[derive(Debug)]
pub struct From {
tables: Vec<TableSource>,
}
impl From {
pub fn new() -> Self {
Self { tables: vec![] }
}
pub(crate) fn push(&mut self, table_source: TableSource) {
self.tables.push(table_source);
}
}
impl Sql for From {
fn sql(&self, mut s: String, ctx: &Context) -> Result<String> {
s.push_str("FROM ");
for (index, table) in self.tables.iter().enumerate() {
if index != self.tables.len() - 1 {
s = table.sql(s, ctx)?;
} else {
s = table.sql(s, ctx)?;
}
}
Ok(s)
}
}