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

Multi column cursor #4

Open
ombr opened this issue Aug 28, 2019 · 1 comment
Open

Multi column cursor #4

ombr opened this issue Aug 28, 2019 · 1 comment

Comments

@ombr
Copy link

ombr commented Aug 28, 2019

Hi,

With a big database, I am using multiple column ordered indexes in order to return item in order. but the limit/offset is not the best thing to do.

I am interested in generating a cursor from multiple columns like this:

  def self.after(cursor = nil)
    query = reorder('created_at DESC, public_id DESC')
    if cursor.present?
      return query.where(
        'cursors.created_at < ? or (cursors.created_at = ? and cursors.public_id < ?)',
        cursor.created_at,
        cursor.created_at,
        cursor.public_id
      )
    end
    query
  end

Do you have plans to do something like this ? I could help.

@Uysim
Copy link
Owner

Uysim commented Aug 29, 2019

@ombr I am happy if you would help in this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants