Skip to content

Commit

Permalink
SeaQLgh-516: use into_sub_query_expr instead of From
Browse files Browse the repository at this point in the history
  • Loading branch information
alphavector committed Apr 27, 2023
1 parent bdd64a0 commit e5f0b64
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ pub enum SimpleExpr {
Constant(Value),
}

pub trait IntoSimpleExpr {
fn into_sub_query_expr(self) -> SimpleExpr;
}

pub(crate) mod private {
use crate::{BinOper, LikeExpr, SimpleExpr, UnOper};

Expand Down Expand Up @@ -2163,12 +2167,6 @@ impl Expression for SimpleExpr {
}
}

impl From<SelectStatement> for SimpleExpr {
fn from(sel: SelectStatement) -> Self {
SimpleExpr::SubQuery(None, Box::new(sel.into_sub_query_statement()))
}
}

impl SimpleExpr {
/// Negates an expression with `NOT`.
///
Expand Down
2 changes: 1 addition & 1 deletion src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl Func {
/// .from(Char::Table)
/// .expr(Func::max(Expr::col(Char::SizeW)))
/// .take()
/// .into(),
/// .into_sub_query_expr(),
/// Expr::col(Char::SizeH).into(),
/// Expr::val(12).into(),
/// ]))
Expand Down
6 changes: 6 additions & 0 deletions src/query/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2317,3 +2317,9 @@ impl ConditionalStatement for SelectStatement {
self
}
}

impl IntoSimpleExpr for SelectStatement {
fn into_sub_query_expr(self) -> SimpleExpr {
SimpleExpr::SubQuery(None, Box::new(self.into_sub_query_statement()))
}
}
6 changes: 3 additions & 3 deletions tests/mysql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,8 @@ fn select_coalesce() {
Query::select()
.from(Char::Table)
.expr(Func::max(Expr::col(Character::Id)))
.to_owned()
.into(),
.take()
.into_sub_query_expr(),
1.into(),
Value::Bool(None).into(),
]))
Expand Down Expand Up @@ -1304,7 +1304,7 @@ fn insert_coalesce() {
.from(Glyph::Table)
.expr(Func::max(Expr::col(Glyph::Aspect)))
.take()
.into(),
.into_sub_query_expr(),
1.into(),
Value::Bool(None).into(),
])
Expand Down
6 changes: 3 additions & 3 deletions tests/postgres/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,8 @@ fn select_coalesce() {
Query::select()
.from(Char::Table)
.expr(Func::count(Expr::col(Character::Id)))
.to_owned()
.into(),
.take()
.into_sub_query_expr(),
1.into(),
Value::Bool(None).into(),
]))
Expand Down Expand Up @@ -1429,7 +1429,7 @@ fn insert_coalesce() {
.from(Glyph::Table)
.expr(Func::max(Expr::col(Glyph::Aspect)))
.take()
.into(),
.into_sub_query_expr(),
1.into(),
Value::Bool(None).into(),
])
Expand Down
4 changes: 2 additions & 2 deletions tests/sqlite/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ fn select_coalesce() {
.from(Char::Table)
.expr(Func::max(Expr::col(Character::Id)))
.to_owned()
.into(),
.into_sub_query_expr(),
1.into(),
Value::Bool(None).into(),
]))
Expand Down Expand Up @@ -1365,7 +1365,7 @@ fn insert_coalesce() {
.from(Glyph::Table)
.expr(Func::max(Expr::col(Glyph::Aspect)))
.take()
.into(),
.into_sub_query_expr(),
1.into(),
Value::Bool(None).into(),
])
Expand Down

0 comments on commit e5f0b64

Please sign in to comment.