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

Make DataStore::instance_fetch_all less ugly #5891

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Jun 13, 2024

This commit rewrites the DataStore::instance_fetch_all query added in
#5888 to perform two separate left joins with the vmm table, so that
the result set only contains a single row. This is a bit more
aesthetically pleasing than having to iterate over a multi-row result
set, but should still return the same values.

Thanks to @jgallagher and @luqmana for figuring out how to do the Diesel
alias!

This commit rewrites the `DataStore::instance_fetch_all` query added in
#5888 to perform two separate left joins with the `vmm` table, so that
the result set only contains a single row. This is a bit more
aesthetically pleasing than having to iterate over a multi-row result
set, but should still return the same values.

Thanks to @jgallagher and @luqmana for figuring out how to do the Diesel
alias!
let (active_vmm, target_vmm) =
diesel::alias!(vmm as active_vmm, vmm as target_vmm);
let vmm_selection =
<Vmm as Selectable<diesel::pg::Pg>>::construct_selection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find! I looked for something like this hanging off of Alias and came up empty.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there was, as far as I can tell, no actual documentation explaining this usage I found it by looking at the implementation of as_select() and noticed that there was a comment on the Selectable trait saying that the return value from construct_selection() was "usually a tuple of fields".

@hawkw hawkw merged commit 42f5332 into main Jun 13, 2024
19 checks passed
@hawkw hawkw deleted the eliza/prettify-instance-fetch-all branch June 13, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants