Giter Site home page Giter Site logo

Comments (4)

billy1624 avatar billy1624 commented on August 16, 2024 1

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(" ")
);

from sea-query.

billy1624 avatar billy1624 commented on August 16, 2024 1

Is this a good idea to add func join_cond() which accept Condtion instead of SimpleExpr ?

Regarding the change of API... I think we can do this without breaking anything and always use Condition internally? @tyt2y3

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
    }
}

from sea-query.

Makiras avatar Makiras commented on August 16, 2024 1

ops! I'm sorry that I didn't read the manual carefully, it works well and thanks a lot.

from sea-query.

tyt2y3 avatar tyt2y3 commented on August 16, 2024

I agree. Yes it seems to be nicer to use Cond:all instead of and chains.

from sea-query.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.