From ce59132e1ceb9baddd0132765deaab9c63c39017 Mon Sep 17 00:00:00 2001 From: andres Date: Sun, 6 Nov 2022 15:44:56 -0500 Subject: [PATCH] Add mul and div for SimpleExpr --- src/expr.rs | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/expr.rs b/src/expr.rs index f27320b60..ff53b6212 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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(self, right: T) -> Self + where + T: Into, + { + 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(self, right: T) -> Self + where + T: Into, + { + self.binary(BinOper::Div, right.into()) + } + /// Perform subtraction with another [`SimpleExpr`]. /// /// # Examples