Skip to content

Commit

Permalink
Change method signature of expr_as to accept self #1979
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Nov 22, 2023
1 parent 8aa49be commit d471c4e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/query/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ pub trait QuerySelect: Sized {
/// "SELECT `cake`.`id`, `cake`.`name`, UPPER(`cake`.`name`) AS `name_upper` FROM `cake`"
/// );
/// ```
///
/// FIXME: change signature to `mut self`
fn expr_as<T, A>(&mut self, expr: T, alias: A) -> &mut Self
where
T: Into<SimpleExpr>,
Expand All @@ -519,6 +521,34 @@ pub trait QuerySelect: Sized {
self.query().expr_as(expr, alias.into_identity());
self
}

/// Owned version of `expr_as`.
///
/// Select column.
///
/// ```
/// use sea_orm::sea_query::{Alias, Expr, Func};
/// use sea_orm::{entity::*, tests_cfg::cake, DbBackend, QuerySelect, QueryTrait};
///
/// assert_eq!(
/// cake::Entity::find()
/// .expr_as(
/// Func::upper(Expr::col((cake::Entity, cake::Column::Name))),
/// "name_upper"
/// )
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name`, UPPER(`cake`.`name`) AS `name_upper` FROM `cake`"
/// );
/// ```
fn expr_as_<T, A>(mut self, expr: T, alias: A) -> Self
where
T: Into<SimpleExpr>,
A: IntoIdentity,
{
self.query().expr_as(expr, alias.into_identity());
self
}
}

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

0 comments on commit d471c4e

Please sign in to comment.