Skip to content

Commit

Permalink
Added QuerySelect::tbl_col_as
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Jun 19, 2024
1 parent a9c2e1b commit 1cdbbd4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/query/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ pub trait QuerySelect: Sized {
self
}

/// Owned version of `expr_as`.
/// Same of `expr_as`. Here for legacy reasons.
///
/// Select column.
///
Expand All @@ -555,6 +555,32 @@ pub trait QuerySelect: Sized {
self.query().expr_as(expr, alias.into_identity());
self
}

/// Shorthand of `expr_as(Expr::col((T, C)), A)`.
///
/// ```
/// use sea_orm::sea_query::{Alias, Expr, Func};
/// use sea_orm::{entity::*, tests_cfg::cake, DbBackend, QuerySelect, QueryTrait};
///
/// assert_eq!(
/// cake::Entity::find()
/// .select_only()
/// .tbl_col_as((cake::Entity, cake::Column::Name), "cake_name")
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`name` AS `cake_name` FROM `cake`"
/// );
/// ```
fn tbl_col_as<T, C, A>(mut self, (tbl, col): (T, C), alias: A) -> Self
where
T: IntoIden + 'static,
C: IntoIden + 'static,
A: IntoIdentity,
{
self.query()
.expr_as(Expr::col((tbl, col)), alias.into_identity());
self
}
}

// LINT: when the column does not appear in tables selected from
Expand Down

0 comments on commit 1cdbbd4

Please sign in to comment.