1use std::borrow::Cow;
2
3use super::SelectQuery;
4
5#[derive(Debug, PartialEq, Clone)]
12pub struct CommonTableExpression<'a> {
13 pub(crate) identifier: Cow<'a, str>,
14 pub(crate) columns: Vec<Cow<'a, str>>,
15 pub(crate) selection: SelectQuery<'a>,
16}
17
18impl<'a> CommonTableExpression<'a> {
19 pub fn column(mut self, column: impl Into<Cow<'a, str>>) -> Self {
22 self.columns.push(column.into());
23 self
24 }
25}
26
27pub trait IntoCommonTableExpression<'a> {
33 fn into_cte(self, identifier: impl Into<Cow<'a, str>>) -> CommonTableExpression<'a>
34 where
35 Self: Into<SelectQuery<'a>>,
36 {
37 CommonTableExpression {
38 identifier: identifier.into(),
39 columns: Vec::new(),
40 selection: self.into(),
41 }
42 }
43}