Allow pagination with a primary key besides :id#2
Merged
kgann merged 3 commits intokgann:masterfrom Aug 3, 2015
Merged
Conversation
src/cumin/pagination.clj
Outdated
Owner
There was a problem hiding this comment.
would (aggregate (count :*) :count) work just as well?
Contributor
Author
There was a problem hiding this comment.
Good question. I could've sworn I'd seen MySQL performing way slower w/ count(*) than w/ count(id) (years ago), but everything I'm seeing now says otherwise (and I don't use MySQL anymore anyway). Will update; that'll be more straightforward.
Owner
There was a problem hiding this comment.
I think using :pk is great but perhaps default to :* instead of assuming there is an :id key.
Contributor
Author
There was a problem hiding this comment.
Oops, I pushed too quick ;) Will update to use the :pk lookup and fall back to :*.
These should be semantically identical (unless the column was nullable), but the code is certainly clearer this way.
Owner
|
👍 Thanks! |
kgann
added a commit
that referenced
this pull request
Aug 3, 2015
Allow pagination with a primary key besides :id
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.
This one is more straightforward than the last one: Korma defaults to a primary key of
:id, but it can be set to something else.There was one small edge case I handled: if there is no primary key, I fall back to trying a column named
:id, just as the existing behavior would've done. I can delete that fallback behavior if you'd prefer to fail fast if there's no primary key.