Skip to content

Allow pagination with a primary key besides :id#2

Merged
kgann merged 3 commits intokgann:masterfrom
trptcolin:pagination-with-nonstandard-pk
Aug 3, 2015
Merged

Allow pagination with a primary key besides :id#2
kgann merged 3 commits intokgann:masterfrom
trptcolin:pagination-with-nonstandard-pk

Conversation

@trptcolin
Copy link
Contributor

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.

Copy link
Owner

Choose a reason for hiding this comment

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

would (aggregate (count :*) :count) work just as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Owner

Choose a reason for hiding this comment

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

I think using :pk is great but perhaps default to :* instead of assuming there is an :id key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.
@kgann
Copy link
Owner

kgann commented Aug 3, 2015

👍 Thanks!

kgann added a commit that referenced this pull request Aug 3, 2015
Allow pagination with a primary key besides :id
@kgann kgann merged commit 767623a into kgann:master Aug 3, 2015
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