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

[issues-344] Improve expr #528

Merged
merged 3 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
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
235 changes: 154 additions & 81 deletions src/expr.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
//! .and_where(
//! Expr::expr(Expr::col(Char::SizeW).add(1))
//! .mul(2)
//! .equals(Expr::expr(Expr::col(Char::SizeH).div(2)).sub(1))
//! .eq(Expr::expr(Expr::col(Char::SizeH).div(2)).sub(1))
//! )
//! .and_where(
//! Expr::col(Char::SizeW).in_subquery(
Expand Down Expand Up @@ -351,7 +351,7 @@
//! .column(Char::Character)
//! .column((Font::Table, Font::Name))
//! .from(Char::Table)
//! .left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
//! .left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
//! .and_where(Expr::col(Char::SizeW).is_in([3, 4]))
//! .and_where(Expr::col(Char::Character).like("A%"))
//! .to_owned();
Expand Down
4 changes: 2 additions & 2 deletions src/query/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl CaseStatement {
/// )
/// .case(
/// Cond::any()
/// .add(Expr::tbl(Character::Table, Character::FontSize).between(24,48).into_condition())
/// .add(Expr::tbl(Character::Table, Character::SizeW).between(300,500).into_condition()),
/// .add(Expr::tbl(Character::Table, Character::FontSize).between(24,48))
/// .add(Expr::tbl(Character::Table, Character::SizeW).between(300,500)),
/// "medium"
/// )
/// .finally("small"),
Expand Down
66 changes: 33 additions & 33 deletions src/query/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .and_where(Expr::col(Char::SizeW).is_in([3, 4]))
/// .and_where(Expr::col(Char::Character).like("A%"))
/// .to_owned();
Expand Down Expand Up @@ -816,7 +816,7 @@ impl SelectStatement {
/// .expr(Expr::asterisk())
/// .from(Char::Table)
/// .from(Font::Table)
/// .and_where(Expr::tbl(Font::Table, Font::Id).equals(Char::Table, Char::FontId))
/// .and_where(Expr::tbl(Font::Table, Font::Id).equals((Char::Table, Char::FontId)))
/// .to_owned();
///
/// assert_eq!(
Expand Down Expand Up @@ -1026,7 +1026,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .cross_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .cross_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .to_owned();
///
/// assert_eq!(
Expand All @@ -1050,8 +1050,8 @@ impl SelectStatement {
/// .cross_join(
/// Font::Table,
/// all![
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// ]
/// )
/// .to_owned();
Expand Down Expand Up @@ -1088,7 +1088,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .to_owned();
///
/// assert_eq!(
Expand All @@ -1112,8 +1112,8 @@ impl SelectStatement {
/// .left_join(
/// Font::Table,
/// all![
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// ]
/// )
/// .to_owned();
Expand Down Expand Up @@ -1150,7 +1150,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .right_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .right_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .to_owned();
///
/// assert_eq!(
Expand All @@ -1174,8 +1174,8 @@ impl SelectStatement {
/// .right_join(
/// Font::Table,
/// all![
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// ]
/// )
/// .to_owned();
Expand Down Expand Up @@ -1212,7 +1212,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .inner_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .inner_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .to_owned();
///
/// assert_eq!(
Expand All @@ -1236,8 +1236,8 @@ impl SelectStatement {
/// .inner_join(
/// Font::Table,
/// all![
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// ]
/// )
/// .to_owned();
Expand Down Expand Up @@ -1274,7 +1274,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .full_outer_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .full_outer_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .to_owned();
///
/// assert_eq!(
Expand All @@ -1294,8 +1294,8 @@ impl SelectStatement {
/// .full_outer_join(
/// Font::Table,
/// all![
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// ]
/// )
/// .to_owned();
Expand Down Expand Up @@ -1328,7 +1328,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .join(JoinType::RightJoin, Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .join(JoinType::RightJoin, Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .to_owned();
///
/// assert_eq!(
Expand All @@ -1353,8 +1353,8 @@ impl SelectStatement {
/// JoinType::RightJoin,
/// Font::Table,
/// all![
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
/// ]
/// )
/// .to_owned();
Expand Down Expand Up @@ -1402,7 +1402,7 @@ impl SelectStatement {
/// JoinType::RightJoin,
/// Font::Table,
/// Alias::new("f"),
/// Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id)
/// Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id))
/// )
/// .to_owned();
///
Expand Down Expand Up @@ -1430,8 +1430,8 @@ impl SelectStatement {
/// Font::Table,
/// Alias::new("f"),
/// Condition::all()
/// .add(Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .add(Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .add(Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .add(Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// )
/// .to_string(MysqlQueryBuilder),
/// r#"SELECT `character`, `font`.`name` FROM `character` RIGHT JOIN `font` AS `f` ON `character`.`font_id` = `font`.`id` AND `character`.`font_id` = `font`.`id`"#
Expand Down Expand Up @@ -1474,7 +1474,7 @@ impl SelectStatement {
/// JoinType::LeftJoin,
/// Query::select().column(Glyph::Id).from(Glyph::Table).take(),
/// sub_glyph.clone(),
/// Expr::tbl(Font::Table, Font::Id).equals(sub_glyph.clone(), Glyph::Id)
/// Expr::tbl(Font::Table, Font::Id).equals((sub_glyph.clone(), Glyph::Id))
/// )
/// .to_owned();
///
Expand All @@ -1501,8 +1501,8 @@ impl SelectStatement {
/// Query::select().column(Glyph::Id).from(Glyph::Table).take(),
/// sub_glyph.clone(),
/// Condition::all()
/// .add(Expr::tbl(Font::Table, Font::Id).equals(sub_glyph.clone(), Glyph::Id))
/// .add(Expr::tbl(Font::Table, Font::Id).equals(sub_glyph.clone(), Glyph::Id))
/// .add(Expr::tbl(Font::Table, Font::Id).equals((sub_glyph.clone(), Glyph::Id)))
/// .add(Expr::tbl(Font::Table, Font::Id).equals((sub_glyph.clone(), Glyph::Id)))
/// )
/// .to_string(MysqlQueryBuilder),
/// r#"SELECT `name` FROM `font` LEFT JOIN (SELECT `id` FROM `glyph`) AS `sub_glyph` ON `font`.`id` = `sub_glyph`.`id` AND `font`.`id` = `sub_glyph`.`id`"#
Expand Down Expand Up @@ -1544,7 +1544,7 @@ impl SelectStatement {
/// JoinType::LeftJoin,
/// Query::select().column(Glyph::Id).from(Glyph::Table).take(),
/// sub_glyph.clone(),
/// Expr::tbl(Font::Table, Font::Id).equals(sub_glyph.clone(), Glyph::Id)
/// Expr::tbl(Font::Table, Font::Id).equals((sub_glyph.clone(), Glyph::Id))
/// )
/// .to_owned();
///
Expand All @@ -1567,8 +1567,8 @@ impl SelectStatement {
/// Query::select().column(Glyph::Id).from(Glyph::Table).take(),
/// sub_glyph.clone(),
/// Condition::all()
/// .add(Expr::tbl(Font::Table, Font::Id).equals(sub_glyph.clone(), Glyph::Id))
/// .add(Expr::tbl(Font::Table, Font::Id).equals(sub_glyph.clone(), Glyph::Id))
/// .add(Expr::tbl(Font::Table, Font::Id).equals((sub_glyph.clone(), Glyph::Id)))
/// .add(Expr::tbl(Font::Table, Font::Id).equals((sub_glyph.clone(), Glyph::Id)))
/// )
/// .to_string(MysqlQueryBuilder),
/// r#"SELECT `name` FROM `font` LEFT JOIN LATERAL (SELECT `id` FROM `glyph`) AS `sub_glyph` ON `font`.`id` = `sub_glyph`.`id` AND `font`.`id` = `sub_glyph`.`id`"#
Expand Down Expand Up @@ -1622,7 +1622,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .join(JoinType::RightJoin, Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .join(JoinType::RightJoin, Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .group_by_columns([
/// Char::Character,
/// ])
Expand All @@ -1649,7 +1649,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .join(JoinType::RightJoin, Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .join(JoinType::RightJoin, Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .group_by_columns([
/// (Char::Table, Char::Character),
/// ])
Expand Down Expand Up @@ -1689,7 +1689,7 @@ impl SelectStatement {
/// .column(Char::Character)
/// .column((Font::Table, Font::Name))
/// .from(Char::Table)
/// .join(JoinType::RightJoin, Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
/// .join(JoinType::RightJoin, Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
/// .group_by_col((Char::Table, Char::Character))
/// .to_owned();
///
Expand Down Expand Up @@ -2221,7 +2221,7 @@ impl SelectStatement {
/// .join(
/// JoinType::InnerJoin,
/// Alias::new("cte_traversal"),
/// Expr::tbl(Alias::new("cte_traversal"), Alias::new("next")).equals(Alias::new("table"), Alias::new("id")).into_condition()
/// Expr::tbl(Alias::new("cte_traversal"), Alias::new("next")).equals((Alias::new("table"), Alias::new("id")))
/// )
/// .to_owned();
///
Expand Down
2 changes: 1 addition & 1 deletion src/query/with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl Cycle {
/// .join(
/// JoinType::InnerJoin,
/// Alias::new("cte_traversal"),
/// Expr::tbl(Alias::new("cte_traversal"), Alias::new("next")).equals(Alias::new("table"), Alias::new("id")).into_condition()
/// Expr::tbl(Alias::new("cte_traversal"), Alias::new("next")).equals((Alias::new("table"), Alias::new("id")))
/// )
/// .to_owned();
///
Expand Down
22 changes: 11 additions & 11 deletions tests/mysql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn select_8() {
Char::Character,
])
.from(Char::Table)
.left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
.left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
.to_string(MysqlQueryBuilder),
"SELECT `character` FROM `character` LEFT JOIN `font` ON `character`.`font_id` = `font`.`id`"
);
Expand All @@ -118,8 +118,8 @@ fn select_9() {
Char::Character,
])
.from(Char::Table)
.left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
.inner_join(Glyph::Table, Expr::tbl(Char::Table, Char::Character).equals(Glyph::Table, Glyph::Image))
.left_join(Font::Table, Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
.inner_join(Glyph::Table, Expr::tbl(Char::Table, Char::Character).equals((Glyph::Table, Glyph::Image)))
.to_string(MysqlQueryBuilder),
"SELECT `character` FROM `character` LEFT JOIN `font` ON `character`.`font_id` = `font`.`id` INNER JOIN `glyph` ON `character`.`character` = `glyph`.`image`"
);
Expand All @@ -134,8 +134,8 @@ fn select_10() {
])
.from(Char::Table)
.left_join(Font::Table,
Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id)
.and(Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id))
Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id))
.and(Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)))
)
.to_string(MysqlQueryBuilder),
"SELECT `character` FROM `character` LEFT JOIN `font` ON (`character`.`font_id` = `font`.`id`) AND (`character`.`font_id` = `font`.`id`)"
Expand Down Expand Up @@ -369,7 +369,7 @@ fn select_25() {
.and_where(
Expr::col(Char::SizeW)
.mul(2)
.equals(Expr::col(Char::SizeH).div(2))
.eq(Expr::col(Char::SizeH).div(2))
)
.to_string(MysqlQueryBuilder),
"SELECT `character` FROM `character` WHERE `size_w` * 2 = `size_h` / 2"
Expand All @@ -385,7 +385,7 @@ fn select_26() {
.and_where(
Expr::expr(Expr::col(Char::SizeW).add(1))
.mul(2)
.equals(Expr::expr(Expr::col(Char::SizeH).div(2)).sub(1))
.eq(Expr::expr(Expr::col(Char::SizeH).div(2)).sub(1))
)
.to_string(MysqlQueryBuilder),
"SELECT `character` FROM `character` WHERE (`size_w` + 1) * 2 = (`size_h` / 2) - 1"
Expand Down Expand Up @@ -437,7 +437,7 @@ fn select_30() {
.and_where(
Expr::col(Char::SizeW).mul(2)
.add(Expr::col(Char::SizeH).div(3))
.equals(4)
.eq(4)
)
.to_string(MysqlQueryBuilder),
"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE (`size_w` * 2) + (`size_h` / 3) = 4"
Expand Down Expand Up @@ -784,7 +784,7 @@ fn select_50() {
.from(Char::Table)
.inner_join(
Font::Table,
Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id),
Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id)),
)
.to_string(MysqlQueryBuilder);

Expand Down Expand Up @@ -881,7 +881,7 @@ fn select_54() {
.expr(Expr::asterisk())
.from(Char::Table)
.from(Font::Table)
.and_where(Expr::tbl(Font::Table, Font::Id).equals(Char::Table, Char::FontId))
.and_where(Expr::tbl(Font::Table, Font::Id).equals((Char::Table, Char::FontId)))
.to_string(MysqlQueryBuilder);

assert_eq!(
Expand Down Expand Up @@ -1372,7 +1372,7 @@ fn union_1() {
.from(Char::Table)
.left_join(
Font::Table,
Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id)
Expr::tbl(Char::Table, Char::FontId).equals((Font::Table, Font::Id))
)
.order_by((Font::Table, Font::Id), Order::Asc)
.take()
Expand Down
Loading