Diesel: Add support for `HAVING` clauses

Created on 27 Nov 2020  路  2Comments  路  Source: diesel-rs/diesel

With #2571 merged diesel now officially supports GROUP BY causes. As mentioned in #210 we have no concrete planes for supporting HAVING clauses in the next release. I've opening this issue to just have one for HAVING clauses + write down some notes for potential contributors. So if anyone is interested in adding support for such clauses feel free to open a PR.

Steps to add support for HAVING clauses:

  • Define a HavingDsl trait similar to the existing FilterDsl trait
  • Add a generic impl for all tables, similar to this impl for FilterDsl.
  • Add support for HAVING clauses to our query builder:

    • Add a NoHavingClause similar to NoWhereClause

    • Add a HavingClause<Expr> similar to WhereClause<Expr>

    • Add another generic field to SelectStatement containing the having clause. Default that generic parameter to NoHavingClause. Add this generic parameter to all impls in that file.

    • Make all of the impls in `diesel/src/query_builder/select_statement/dsl_impl.rs generic over the new generic paramater.

    • Fix all compilation errors coming from the newly added field by forwarding the having clause to the newly constructed select statement structs.

    • Implement HavingDsl for SelectStatement

    • Add another boxed field to BoxedSelectStatement containing the boxed HAVING clause

    • Implement HavingDsl for SelectStatement

  • Add a helper type to diesel::dsl (Similar to diesel::dsl::Filter<Source, Filter>
  • Add a having method + some documentation to QueryDsl, similar to filter()
  • Add a few tests to diesel_tests
enhancement good first issue help wanted mentoring available

Most helpful comment

I would like to work on this issue

All 2 comments

I would like to work on this issue

@dnamsons Sure, go for it. If you hit any issue feel free to reach out for me here or in our gitter channel. Opening a WIP PR is also probably a good idea to get early feedback on the implementation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

killercup picture killercup  路  4Comments

gliderkite picture gliderkite  路  3Comments

kollapsderwellenfunktion picture kollapsderwellenfunktion  路  4Comments

jimmycuadra picture jimmycuadra  路  4Comments

sgrif picture sgrif  路  4Comments