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 upAuto-generated query methods #1358
Comments
This comment has been minimized.
|
I don't think that these methods would be significantly easier to use than using the query builder directly. Generally we try to keep Diesel very clear what underlying SQL is being performed. I think this would make a great candidate for a third party library, but I don't think it makes sense for Diesel at this time. |
sgrif
closed this
Dec 9, 2017
This comment has been minimized.
|
https://git.bananium.fr/enib/enibar/blob/master/application/rapi/rapi_codegen/src/model.rs#L31-56 Here's what I'm doing in a project (for now it's minimal but I intend to expand it as the migration from python to rust progresses), if there is an interest I guess I could release it as a |
This comment has been minimized.
|
@Eijebong I used what you wrote as a base for building this library: https://github.com/shssoichiro/diesel-derives-extra. It's a little rough for now but I'll clean it up and probably add more methods as feedback is generated from using it. I think the main benefit of putting this into diesel itself would be that the traits could be pulled in with |
shssoichiro commentedDec 8, 2017
•
edited
In Diesel, I'd like the ability to auto-derive query methods onto my model. For example, if I have the following code:
I'd like to see the following method derived:
Likewise for selects, a few examples:
Would generate something like this:
The following:
Would generate this:
And this derive:
would generate this:
As a more advanced version of this feature, I'd like to be able to define queries with basic filters and sorts using auto-derive as I can in Hibernate. For example, something like this:
would generate standard Diesel DSL like this:
Each of these features would reduce the amount of DSL needed to be manually written (users would only need to resort to DSL for more complex queries) by deriving the most frequently used types of queries (CRUD) within a typical service, would help users to get up and running with Diesel more quickly with less upfront knowledge needed, and would reduce the amount of code needed to be maintained (and copy and pasted) by users. I'd be willing to help implement this as well, if this feature is accepted and API agreed upon.