https://github.com/tsuwatch/activerecord-cursor
cursor pagination for ActiveRecord
https://github.com/tsuwatch/activerecord-cursor
Last synced: 2 months ago
JSON representation
cursor pagination for ActiveRecord
- Host: GitHub
- URL: https://github.com/tsuwatch/activerecord-cursor
- Owner: tsuwatch
- Created: 2018-12-30T20:23:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-16T06:17:24.000Z (about 5 years ago)
- Last Synced: 2025-03-15T06:15:58.397Z (3 months ago)
- Language: Ruby
- Size: 21.5 KB
- Stars: 11
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ActiveRecord::Cursor
cursor pagination for ActiveRecord
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'activerecord-cursor'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install activerecord-cursor
## Usage
```ruby
Post.all
=> [
#,
#,
#,
#
]
Post.cursor(key: :created_at)
=> [#]
Post.where(published: true).cursor(key: :created_at, reverse: true)
=> [#]
Post.where(published: true).cursor(key: :created_at, reverse: true, start: Post.next_cursor) # Get next page
=> [#]
Post.where(published: true).cursor(key: :created_at, reverse: true, stop: Post.prev_cursor) # Get previous page
=> [#]
```### Options
- `key`: Cursor key. Defult: 'id'
- `reverse`: Set it to true, if your set are ordered descendingly (DESC). Default: false
- `size`: Page size. Default: 1
- `start`: Cursor value
- `stop`: Cursor value## Development
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/tsuwatch/activerecord-cursor.