-
Is this a good idea to add func Currently sea-query has function pub fn join<R>(
&mut self,
join: JoinType,
tbl_ref: R,
condition: SimpleExpr
) -> &mut Self which means it can construct query such as SELECT a.id, b.id FROM a
LEFT JOIN b ON a.time=b.time
WHERE a.cost > 0; but if we want construct query as SELECT a.id, b.id FROM a
LEFT JOIN b ON ( a.time=b.time AND a.cost=b.cost )
WHERE a.cost > 0; maybe |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hi @Makiras, I guess what you want is something like this? let query = Query::select()
.column(Char::Character)
.table_column(Font::Table, Font::Name)
.from(Char::Table)
.join(
JoinType::RightJoin,
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))
.and(Expr::tbl(Char::Table, Char::FontId).equals(Font::Table, Font::Id)),
)
.group_by_columns(vec![(Char::Table, Char::Character)])
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
[
r#"SELECT `character`, `font`.`name`"#,
r#"FROM `character`"#,
r#"RIGHT JOIN `font` ON (`character`.`font_id` = `font`.`id`)"#,
r#"AND (`character`.`font_id` = `font`.`id`)"#,
r#"AND (`character`.`font_id` = `font`.`id`)"#,
r#"GROUP BY `character`.`character`"#
]
.join(" ")
); |
Beta Was this translation helpful? Give feedback.
-
Regarding the change of API... I think we can do this without breaking anything and always use pub fn join<R, C>(&mut self, join: JoinType, tbl_ref: R, condition: C) -> &mut Self
where
R: IntoTableRef,
C: IntoCondition,
{
// ...
} Considering we have... impl IntoCondition for SimpleExpr {
fn into_condition(self) -> Condition {
Condition::all().add(self)
}
}
impl IntoCondition for Condition {
fn into_condition(self) -> Condition {
self
}
} |
Beta Was this translation helpful? Give feedback.
-
ops! I'm sorry that I didn't read the manual carefully, it works well and thanks a lot. |
Beta Was this translation helpful? Give feedback.
-
I agree. Yes it seems to be nicer to use |
Beta Was this translation helpful? Give feedback.
Hi @Makiras, I guess what you want is something like this?