sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Distinct support?

Open edg-l opened this issue 3 years ago • 7 comments

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

edg-l avatar Oct 28 '21 08:10 edg-l

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.

billy1624 avatar Oct 28 '21 08:10 billy1624

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

baoyachi avatar Oct 28 '21 08:10 baoyachi

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

edg-l avatar Oct 28 '21 08:10 edg-l

@edg-l we add support for some types of DISTINCT into sea-query! PR: https://github.com/SeaQL/sea-query/pull/313

ikrivosheev avatar May 15 '22 22:05 ikrivosheev

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

billy1624 avatar Jul 12 '22 04:07 billy1624

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?

kyoto7250 avatar Jul 20 '22 05:07 kyoto7250

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:

  • https://github.com/SeaQL/sea-orm/blob/1385b749cbf6425c62bf2c7cf060d655f1a649dc/src/query/helper.rs#L15-L47
  • 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 avatar Jul 20 '22 10:07 billy1624