Skip to content

Commit

Permalink
Merge pull request #206 from SeaQL/add-col-schema-tbl-col
Browse files Browse the repository at this point in the history
Add `ColumnRef::SchemaTableColumn`
  • Loading branch information
tyt2y3 authored Dec 24, 2021
2 parents 63b7288 + 9ae3261 commit 8ad6fbf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/backend/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ pub trait QueryBuilder: QuotedBuilder {
write!(sql, ".").unwrap();
column.prepare(sql, self.quote());
}
ColumnRef::SchemaTableColumn(schema, table, column) => {
schema.prepare(sql, self.quote());
write!(sql, ".").unwrap();
table.prepare(sql, self.quote());
write!(sql, ".").unwrap();
column.prepare(sql, self.quote());
}
};
}
SimpleExpr::Tuple(exprs) => {
Expand Down
22 changes: 22 additions & 0 deletions src/query/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,28 @@ impl SelectStatement {
/// r#"SELECT `character`.`character` FROM `character`"#
/// );
/// ```
///
/// ```
/// use sea_query::{tests_cfg::*, *};
///
/// let query = Query::select()
/// .from(Char::Table)
/// .column((Alias::new("schema"), Char::Table, Char::Character))
/// .to_owned();
///
/// assert_eq!(
/// query.to_string(MysqlQueryBuilder),
/// r#"SELECT `schema`.`character`.`character` FROM `character`"#
/// );
/// assert_eq!(
/// query.to_string(PostgresQueryBuilder),
/// r#"SELECT "schema"."character"."character" FROM "character""#
/// );
/// assert_eq!(
/// query.to_string(SqliteQueryBuilder),
/// r#"SELECT `schema`.`character`.`character` FROM `character`"#
/// );
/// ```
pub fn column<C>(&mut self, col: C) -> &mut Self
where
C: IntoColumnRef,
Expand Down
12 changes: 12 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl fmt::Debug for dyn Iden {
pub enum ColumnRef {
Column(DynIden),
TableColumn(DynIden, DynIden),
SchemaTableColumn(DynIden, DynIden, DynIden),
}

pub trait IntoColumnRef {
Expand Down Expand Up @@ -262,6 +263,17 @@ where
}
}

impl<S: 'static, T: 'static, U: 'static> IntoColumnRef for (S, T, U)
where
S: IntoIden,
T: IntoIden,
U: IntoIden,
{
fn into_column_ref(self) -> ColumnRef {
ColumnRef::SchemaTableColumn(self.0.into_iden(), self.1.into_iden(), self.2.into_iden())
}
}

impl IntoTableRef for TableRef {
fn into_table_ref(self) -> TableRef {
self
Expand Down

0 comments on commit 8ad6fbf

Please sign in to comment.