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

Add mul and div for SimpleExpr #510

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,80 @@ impl SimpleExpr {
self.binary(BinOper::Add, right.into())
}

/// Perform multiplication with another [`SimpleExpr`].
///
/// # Examples
///
/// ```
/// use sea_query::{tests_cfg::*, *};
///
/// let query = Query::select()
/// .expr(
/// Expr::col(Char::SizeW)
/// .max()
/// .mul(Expr::col(Char::SizeH).max()),
/// )
/// .from(Char::Table)
/// .to_owned();
///
/// assert_eq!(
/// query.to_string(MysqlQueryBuilder),
/// r#"SELECT MAX(`size_w`) * MAX(`size_h`) FROM `character`"#
/// );
/// assert_eq!(
/// query.to_string(PostgresQueryBuilder),
/// r#"SELECT MAX("size_w") * MAX("size_h") FROM "character""#
/// );
/// assert_eq!(
/// query.to_string(SqliteQueryBuilder),
/// r#"SELECT MAX("size_w") * MAX("size_h") FROM "character""#
/// );
/// ```
#[allow(clippy::should_implement_trait)]
pub fn mul<T>(self, right: T) -> Self
where
T: Into<SimpleExpr>,
{
self.binary(BinOper::Mul, right.into())
}

/// Perform division with another [`SimpleExpr`].
///
/// # Examples
///
/// ```
/// use sea_query::{tests_cfg::*, *};
///
/// let query = Query::select()
/// .expr(
/// Expr::col(Char::SizeW)
/// .max()
/// .div(Expr::col(Char::SizeH).max()),
/// )
/// .from(Char::Table)
/// .to_owned();
///
/// assert_eq!(
/// query.to_string(MysqlQueryBuilder),
/// r#"SELECT MAX(`size_w`) / MAX(`size_h`) FROM `character`"#
/// );
/// assert_eq!(
/// query.to_string(PostgresQueryBuilder),
/// r#"SELECT MAX("size_w") / MAX("size_h") FROM "character""#
/// );
/// assert_eq!(
/// query.to_string(SqliteQueryBuilder),
/// r#"SELECT MAX("size_w") / MAX("size_h") FROM "character""#
/// );
/// ```
#[allow(clippy::should_implement_trait)]
pub fn div<T>(self, right: T) -> Self
where
T: Into<SimpleExpr>,
{
self.binary(BinOper::Div, right.into())
}

/// Perform subtraction with another [`SimpleExpr`].
///
/// # Examples
Expand Down