Add Repo.select_all #4733
Closed
dkuku wants to merge 1 commit into
Closed
Conversation
Member
|
Thank you but unfortunately I don't believe it is worth enlarging the Ecto API for this functionality. Doing a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I proposed this on the Google Group but didn't receive any replies. This has been sitting on my disk, so I'll try to at least get it upstream.
I think this is a missing piece — we have
insert_all,delete_all, andupdate_all, all of which return the count, but there's no equivalent for select. Currently,Repo.allhas the count available internally but callselem(1)on the tuple, so when we actually need the count we have two options:Enum.count/1on the results.Repo.aggregate.I think this fits nicely inside the current api - you have either the long version
select_allthat gives you the full result with count, or the short versionallthat gives you only the result.The count is useful with pagination
Examples:
https://github.com/duffelhq/paginator/blob/main/lib/paginator.ex#L329 uses Enum.count
https://github.com/mojotech/scrivener_ecto/blob/main/lib/scrivener/paginater/ecto/query.ex#L71 uses sql count
https://github.com/ash-project/ash/blob/main/lib/ash/actions/read/relationships.ex#L1617 uses Enum.split(limit) and checks if there is anything left