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

Distinct support? #275

Closed
edg-l opened this issue Oct 28, 2021 · 7 comments · Fixed by #902
Closed

Distinct support? #275

edg-l opened this issue Oct 28, 2021 · 7 comments · Fixed by #902
Assignees
Labels
good first issue Good for newcomers
Milestone

Comments

@edg-l
Copy link

edg-l commented Oct 28, 2021

I saw sea-query supports it, but It doesn't seem like it's supported yet in sea-orm.

@billy1624
Copy link
Member

Hey @edg-l, welcome! The DISTINCT syntax is not yet supported in sea-orm. However, I believe you can use GROUP BY to construct similar query.

@baoyachi
Copy link
Contributor

baoyachi commented Oct 28, 2021

it's support by sea-query crates @edg-l .

@edg-l
Copy link
Author

edg-l commented Oct 28, 2021

group by does the trick for now, still would be awesome to have distinct supported

@ikrivosheev
Copy link
Member

ikrivosheev commented May 15, 2022

@edg-l we add support for some types of DISTINCT into sea-query!
PR: SeaQL/sea-query#313

@billy1624
Copy link
Member

billy1624 commented Jul 12, 2022

I'll open this issue for contributions. With support of DISTINCT in SeaQuery, we could bring it to SeaORM for sure :)

@billy1624 billy1624 added the good first issue Good for newcomers label Jul 12, 2022
@billy1624 billy1624 moved this from Triage to Open for Contributions in SeaQL Dev Tracker Jul 12, 2022
@billy1624 billy1624 moved this to Triage in SeaQL Dev Tracker Jul 12, 2022
@kyoto7250
Copy link
Contributor

kyoto7250 commented Jul 20, 2022

Hi, I am interested in this issue.

I'd like to work on this issue, so could you tell me a little more about it?

@billy1624
Copy link
Member

Hey @kyoto7250, thanks for the interest! I have a rough idea for it. Please share your thoughts as well :)

In SeaQuery select statement, there are two methods to construct distinct select:

  • sea_query::SelectStatement::distinct()
  • sea_query::SelectStatement::distinct_on()

https://github.com/SeaQL/sea-query/blob/563dd26d3a0b20c24fcca8904afb5849aab9de31/src/query/select.rs#L314-L376

We just simply introduce these two methods into sea_orm::QuerySelect. Similar to what we did for the sea_orm::QuerySelect::column() method:

  • pub trait QuerySelect: Sized {
    #[allow(missing_docs)]
    type QueryStatement;
    /// Add the select SQL statement
    fn query(&mut self) -> &mut SelectStatement;
    /// Clear the selection list
    fn select_only(mut self) -> Self {
    self.query().clear_selects();
    self
    }
    /// Add a select column
    /// ```
    /// use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
    ///
    /// assert_eq!(
    /// cake::Entity::find()
    /// .select_only()
    /// .column(cake::Column::Name)
    /// .build(DbBackend::Postgres)
    /// .to_string(),
    /// r#"SELECT "cake"."name" FROM "cake""#
    /// );
    /// ```
    fn column<C>(mut self, col: C) -> Self
    where
    C: ColumnTrait,
    {
    self.query().expr(col.into_simple_expr());
    self
    }
  • we should have docs and examples for each method
  • also, sea_orm::QuerySelect::column() docs should state this method is applicable to PostgreSQL only

@billy1624 billy1624 moved this from Open for Contributions to Review in SeaQL Dev Tracker Jul 26, 2022
@billy1624 billy1624 moved this from Review to Next Up in SeaQL Dev Tracker Aug 2, 2022
@billy1624 billy1624 added this to the 0.10.x milestone Aug 24, 2022
@billy1624 billy1624 moved this from Next Up to Review in SeaQL Dev Tracker Aug 24, 2022
@billy1624 billy1624 moved this from Review to Done in SeaQL Dev Tracker Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants