Skip to content

Commit

Permalink
Rename SelectStatement::*_alias to *_as
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Mar 5, 2021
1 parent e9a5ea6 commit a210826
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [

[package]
name = "sea-query"
version = "0.6.0"
version = "0.6.1"
authors = [ "Billy Chan <[email protected]>" ]
edition = "2018"
description = "A database agnostic runtime query builder for Rust"
Expand Down
51 changes: 39 additions & 12 deletions src/query/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -522,7 +522,7 @@ impl SelectStatement {
/// r#"SELECT `character` AS `C` FROM `character`"#
/// );
/// ```
pub fn expr_alias<T, A: 'static>(&mut self, expr: T, alias: A) -> &mut Self
pub fn expr_as<T, A: 'static>(&mut self, expr: T, alias: A) -> &mut Self
where T: Into<SimpleExpr>, A: Iden {
self.expr(SelectExpr {
expr: expr.into(),
Expand All @@ -531,6 +531,15 @@ impl SelectStatement {
self
}

#[deprecated(
since = "0.6.1",
note = "Please use the [`SelectStatement::expr_as`] instead"
)]
pub fn expr_alias<T, A: 'static>(&mut self, expr: T, alias: A) -> &mut Self
where T: Into<SimpleExpr>, A: Iden {
self.expr_as(expr, alias)
}

/// From table.
pub fn from<T: 'static>(&mut self, table: T) -> &mut Self
where T: Iden {
Expand All @@ -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!(
Expand All @@ -570,13 +579,22 @@ impl SelectStatement {
/// r#"SELECT `char`.`character` FROM `character` AS `char`"#
/// );
/// ```
pub fn from_as<T: 'static, Y: 'static>(&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<T: 'static, Y: 'static>(&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<dyn Iden>, alias: Rc<dyn Iden>) -> &mut Self {
/// From table with alias, variation of [`SelectStatement::from_as`].
pub fn from_as_dyn(&mut self, table: Rc<dyn Iden>, alias: Rc<dyn Iden>) -> &mut Self {
self.from_from(TableRef::TableAlias(table, alias));
self
}
Expand Down Expand Up @@ -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"),
Expand All @@ -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<T: 'static, A: 'static>(&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<T: 'static, A: 'static>(&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<dyn Iden>, alias: Rc<dyn Iden>, 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<dyn Iden>, alias: Rc<dyn Iden>, condition: SimpleExpr) -> &mut Self {
self.join_join(join, TableRef::TableAlias(table, alias), JoinOn::Condition(Box::new(condition)))
}

Expand Down
2 changes: 1 addition & 1 deletion tests/mysql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
Expand Down
2 changes: 1 addition & 1 deletion tests/postgres/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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""#
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlite/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
Expand Down

0 comments on commit a210826

Please sign in to comment.