Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1696 fix #1702

Merged
merged 12 commits into from
Jun 13, 2023
2 changes: 1 addition & 1 deletion build-tools/docker-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Delete all containers
# $ docker rm -f $(docker ps -a -q)
#
# Delete all volumns
# Delete all volumes
# $ docker volume rm $(docker volume ls -q)
#
# Delete all images
Expand Down
51 changes: 51 additions & 0 deletions src/query/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,57 @@ pub trait QuerySelect: Sized {
self.query().lock_exclusive();
self
}

/// Add an expression to the select expression list.
/// ```
/// use sea_orm::QueryTrait;
/// use sea_orm::{entity::*, query::QuerySelect, tests_cfg::cake, DbBackend};
/// use sea_query::{Alias, Expr};
/// let mut find = cake::Entity::find();
///
/// assert_eq!(
/// cake::Entity::find()
/// .expr(Expr::col(Alias::new("some_column")))
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name`, `some_column` FROM `cake`"
/// );
/// ```
fn expr<T>(mut self, expr: T) -> Self
where
T: Into<SelectExpr>,
{
self.query().expr(expr);
self
}

/// Add select expressions from vector of [`SelectExpr`].
/// ```
/// use sea_orm::QueryTrait;
/// use sea_orm::{entity::*, query::QuerySelect, tests_cfg::cake, DbBackend};
/// use sea_query::{Alias, Expr};
/// let mut find = cake::Entity::find();
///
/// assert_eq!(
/// // new method
darkmmon marked this conversation as resolved.
Show resolved Hide resolved
/// cake::Entity::find()
/// .exprs([
/// Expr::col(Alias::new("some_column")),
/// Expr::col(Alias::new("some_other_column")),
billy1624 marked this conversation as resolved.
Show resolved Hide resolved
/// ])
/// .build(DbBackend::MySql)
/// .to_string(),
/// "SELECT `cake`.`id`, `cake`.`name`, `some_column`, `some_other_column` FROM `cake`"
/// );
/// ```
fn exprs<T, I>(mut self, exprs: I) -> Self
where
T: Into<SelectExpr>,
I: IntoIterator<Item = T>,
{
self.query().exprs(exprs);
self
}
}

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