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

Move query join logic into common functions #2763

Closed
dessalines opened this issue Feb 23, 2023 · 1 comment · Fixed by #3663
Closed

Move query join logic into common functions #2763

dessalines opened this issue Feb 23, 2023 · 1 comment · Fixed by #3663

Comments

@dessalines
Copy link
Member

All the views have a list version, and a single get version. IE getting a post, and fetching a list of posts.

These views have to do the exact joins, but currently this join code is duplicated. It should probably be possible to move this join logic into a common function to be used by both the single get, and the list versions.

@dessalines
Copy link
Member Author

From the diesel chat:

<@happydooby:matrix.org> Question: I have two methods that both require the same joins ( one that fetches a single result with first(), and the other that does a boxed query of many results) so I'd like to extract this into a SelectStatement to a common function.

When I do this, it creates an extremely complicated type, with a lot of internally private diesel functions like JoinOn and Grouped. The type is very unwieldy too.

Is there any way to easily do this, or am I stuck with copy-pasting the join query?

You want to use the types from diesel::dsl for that. They hide those internal private types. The documentation of QueryDsl shows the correct type. For example for users::table.select(users::name) you would look at QueryDsl::select, which states that it returns Select<Self, Selection> where Self is the type you called select onto, and Selection is the argument passed to the function. That would result in diesel::dsl::Select<users::table, users::name> as correct public nameable type for that statement.

dessalines added a commit that referenced this issue Feb 25, 2023
- Also change the ViewToVec, to work with non-vector cases. Might be
  necessary in preparation for #2763
- Fixes #2712
Nutomic added a commit that referenced this issue Mar 1, 2023
* Get rid of Safe Views, use serde_skip

- Also change the ViewToVec, to work with non-vector cases. Might be
  necessary in preparation for #2763
- Fixes #2712

* Forgot one safe

---------

Co-authored-by: Nutomic <me@nutomic.com>
dessalines added a commit that referenced this issue Apr 26, 2023
* Get rid of Safe Views, use serde_skip

- Also change the ViewToVec, to work with non-vector cases. Might be
  necessary in preparation for #2763
- Fixes #2712

* Forgot one safe

---------

Co-authored-by: Nutomic <me@nutomic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant