No commit activity in last 3 years
No release in over 3 years
Adds support to Sequel for easy cursor based pagination on datasets
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.8

Runtime

~> 5.0
 Project Readme

Sequel::KeysetPagination

Build Status

Adds support to Sequel Dataset with both an before and after cursor. Allowing you to slice your dataset in both directions.

Provides cursor support for Relay like pagination: https://facebook.github.io/relay/graphql/connections.htm

To install

# Activate the extension:
Sequel::Database.extension :keyset_pagination
# or
DB.extension :keyset_pagination

Simple pagination example

# Activate the extension:
Sequel::Database.extension :keyset_pagination
# or
DB.extension :keyset_pagination

# Get your first collection of records
DB[:records].order(:id).limit(10)

# Pass the last record's ID as the seek cursor to get the next page
DB[:records].order(:id).limit(5).seek(after: 1125)
# SELECT * FROM `records` WHERE (`id` > 1125) ORDER BY `id` LIMIT 5

Multiple column ordering (example tv episodes)

# To get all episodes after episode 5 of season 1:
DB[:episodes].order(:season_nr, :ep_nr).limit(5).seek(after: [1, 5])
# SELECT * FROM `episodes` WHERE (((`ep_nr` > 5) AND (`season_nr` = 1)) OR (`season_nr` > 1)) ORDER BY `season_nr`, `ep_nr` LIMIT 5

In the above example, both 1x06 up to 1x20 and all future episodes after s02 will be includes in the dataset.

Slicing in both directions

# You can pass both an `after` and `before` cursor to seek
DB[:posts].order(:created_at).seek(before: '2018-10-02T15:00:00Z', after: '2016-10-02T15:00:00Z')
# SELECT * FROM `posts` WHERE ((`created_at` > '2016-10-02T15:00:00Z') AND (`created_at` < '2018-10-02T15:00:00Z')) ORDER BY `created_at`

This will slice your dataset between those two cursors. An unlimited amount of sort columns are supported.