diff --git a/Cargo.toml b/Cargo.toml index b47e4818e..f2777daa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ [package] name = "sea-query" -version = "0.6.0" +version = "0.6.1" authors = [ "Billy Chan " ] edition = "2018" description = "A database agnostic runtime query builder for Rust" diff --git a/src/query/select.rs b/src/query/select.rs index 792e795b1..efbbc8bcc 100644 --- a/src/query/select.rs +++ b/src/query/select.rs @@ -506,7 +506,7 @@ impl SelectStatement { /// /// let query = Query::select() /// .from(Char::Table) - /// .expr_alias(Expr::col(Char::Character), Alias::new("C")) + /// .expr_as(Expr::col(Char::Character), Alias::new("C")) /// .to_owned(); /// /// assert_eq!( @@ -522,7 +522,7 @@ impl SelectStatement { /// r#"SELECT `character` AS `C` FROM `character`"# /// ); /// ``` - pub fn expr_alias(&mut self, expr: T, alias: A) -> &mut Self + pub fn expr_as(&mut self, expr: T, alias: A) -> &mut Self where T: Into, A: Iden { self.expr(SelectExpr { expr: expr.into(), @@ -531,6 +531,15 @@ impl SelectStatement { self } + #[deprecated( + since = "0.6.1", + note = "Please use the [`SelectStatement::expr_as`] instead" + )] + pub fn expr_alias(&mut self, expr: T, alias: A) -> &mut Self + where T: Into, A: Iden { + self.expr_as(expr, alias) + } + /// From table. pub fn from(&mut self, table: T) -> &mut Self where T: Iden { @@ -550,11 +559,11 @@ impl SelectStatement { /// ``` /// use sea_query::{*, tests_cfg::*}; /// - /// let table_alias = Alias::new("char"); + /// let table_as = Alias::new("char"); /// /// let query = Query::select() - /// .from_alias(Char::Table, table_alias.clone()) - /// .table_column(table_alias, Char::Character) + /// .from_as(Char::Table, table_as.clone()) + /// .table_column(table_as, Char::Character) /// .to_owned(); /// /// assert_eq!( @@ -570,13 +579,22 @@ impl SelectStatement { /// r#"SELECT `char`.`character` FROM `character` AS `char`"# /// ); /// ``` + pub fn from_as(&mut self, table: T, alias: Y) -> &mut Self + where T: Iden, Y: Iden { + self.from_as_dyn(Rc::new(table), Rc::new(alias)) + } + + #[deprecated( + since = "0.6.1", + note = "Please use the [`SelectStatement::from_as`] instead" + )] pub fn from_alias(&mut self, table: T, alias: Y) -> &mut Self where T: Iden, Y: Iden { - self.from_alias_dyn(Rc::new(table), Rc::new(alias)) + self.from_as(table, alias) } - /// From table with alias, variation of [`SelectStatement::from_alias`]. - pub fn from_alias_dyn(&mut self, table: Rc, alias: Rc) -> &mut Self { + /// From table with alias, variation of [`SelectStatement::from_as`]. + pub fn from_as_dyn(&mut self, table: Rc, alias: Rc) -> &mut Self { self.from_from(TableRef::TableAlias(table, alias)); self } @@ -757,7 +775,7 @@ impl SelectStatement { /// .column(Char::Character) /// .table_column(Font::Table, Font::Name) /// .from(Char::Table) - /// .join_alias( + /// .join_as( /// JoinType::RightJoin, /// Font::Table, /// Alias::new("f"), @@ -778,13 +796,22 @@ impl SelectStatement { /// r#"SELECT `character`, `font`.`name` FROM `character` RIGHT JOIN `font` AS `f` ON `character`.`font_id` = `font`.`id`"# /// ); /// ``` + pub fn join_as(&mut self, join: JoinType, table: T, alias: A, condition: SimpleExpr) -> &mut Self + where T: Iden, A: Iden { + self.join_as_dyn(join, Rc::new(table), Rc::new(alias), condition) + } + + #[deprecated( + since = "0.6.1", + note = "Please use the [`SelectStatement::join_as`] instead" + )] pub fn join_alias(&mut self, join: JoinType, table: T, alias: A, condition: SimpleExpr) -> &mut Self where T: Iden, A: Iden { - self.join_alias_dyn(join, Rc::new(table), Rc::new(alias), condition) + self.join_as(join, table, alias, condition) } - /// Join with other table by [`JoinType`] and alias, variation of [`SelectStatement::join_alias`]. - pub fn join_alias_dyn(&mut self, join: JoinType, table: Rc, alias: Rc, condition: SimpleExpr) -> &mut Self { + /// Join with other table by [`JoinType`] and alias, variation of [`SelectStatement::join_as`]. + pub fn join_as_dyn(&mut self, join: JoinType, table: Rc, alias: Rc, condition: SimpleExpr) -> &mut Self { self.join_join(join, TableRef::TableAlias(table, alias), JoinOn::Condition(Box::new(condition))) } diff --git a/tests/mysql/query.rs b/tests/mysql/query.rs index 4555267bd..758746821 100644 --- a/tests/mysql/query.rs +++ b/tests/mysql/query.rs @@ -481,7 +481,7 @@ fn select_31() { fn select_32() { assert_eq!( Query::select() - .expr_alias(Expr::col(Char::Character), Alias::new("C")) + .expr_as(Expr::col(Char::Character), Alias::new("C")) .from(Char::Table) .to_string(MysqlQueryBuilder), "SELECT `character` AS `C` FROM `character`" diff --git a/tests/postgres/query.rs b/tests/postgres/query.rs index b361d8b89..057ec6b80 100644 --- a/tests/postgres/query.rs +++ b/tests/postgres/query.rs @@ -481,7 +481,7 @@ fn select_31() { fn select_32() { assert_eq!( Query::select() - .expr_alias(Expr::col(Char::Character), Alias::new("C")) + .expr_as(Expr::col(Char::Character), Alias::new("C")) .from(Char::Table) .to_string(PostgresQueryBuilder), r#"SELECT "character" AS "C" FROM "character""# diff --git a/tests/sqlite/query.rs b/tests/sqlite/query.rs index 8d2cd6798..521b2fc1a 100644 --- a/tests/sqlite/query.rs +++ b/tests/sqlite/query.rs @@ -481,7 +481,7 @@ fn select_31() { fn select_32() { assert_eq!( Query::select() - .expr_alias(Expr::col(Char::Character), Alias::new("C")) + .expr_as(Expr::col(Char::Character), Alias::new("C")) .from(Char::Table) .to_string(SqliteQueryBuilder), "SELECT `character` AS `C` FROM `character`"