Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upA less boilerplaty way of specifying a boxed `ORDER BY` with multiple clauses? #1311
Comments
This comment has been minimized.
|
Short answer to answer the question: No, I don't think there is a less boilerplate-ey way to do this in 0.16/0.99 Longer answer for people looking to take a crack at this: Ultimately the issue here comes from the fact that they are trying to have an unknown number of columns in their order clause. Unlike some other ORMs, Diesel has chosen to override the previous value for all query builder operations besides The reasoning behind this is that it's unclear whether the order given last by the user should be considered more important or less important. Most members of the Rails team consider the behavior of order to be a mistake. The only reason While I don't want to discount this use case, it is definitely one that is less common, which is why it was de-prioritized in favor of the tuple-based API that is causing pain here. I don't have any ideas on what this API should look like. Perhaps it'd make sense to have an API that takes a |
sgrif
referenced this issue
Nov 30, 2017
Closed
creating a dsl ordering var from String parameters #1322
This comment has been minimized.
|
I'm moving this to the 1.0 milestone. I'm pretty sure we can make passing a |
sgrif
added this to the 1.0 milestone
Dec 2, 2017
This comment has been minimized.
|
Never mind, this will require a separate method... |
sgrif
removed this from the 1.0 milestone
Dec 2, 2017
This comment has been minimized.
|
Thanks for the explanation! I presume that adding this method only really makes sense on a boxed query, and hence should only be implemented for |
This comment has been minimized.
|
No, it makes sense for unboxed queries as well. |
sgrif
added this to the 1.2 milestone
Jan 17, 2018
This comment has been minimized.
|
I think I am going to restrict this to boxed queries, and go with the name
I'm open to alternative APIs if anyone has ideas. |
This comment has been minimized.
|
Hmm, maybe |
blakepettersson commentedNov 25, 2017
•
edited
Problem Description
I have a use case where I want to dynamically set an order by clause via some request parameters. I have an example entity below,
Todo:Doing a boxed query works fine:
What are you trying to accomplish?
While this works great, I was wondering if there's a simpler/shorter way of accomplishing the same thing. According to the documentation, an
orderclause will override any other order clause. Ideally I'd like an API that would work something like this, where any order clauses would be appended instead of replacing any previous order clauses:Is there an API that already does this with Diesel, and/or would it be possible to achieve (with current Rust stable)? If it is hypothetically possible but not currently available, I'd be happy to look into this if someone can point me in the right way :)
Checklist