# Using ROM pagination plugin

ROM.rb has paginaton plugin available and luckily Anton Davydov has already written an integration of it into Hanami's Repository class

Gemfile

gem 'hanami-pagination', '~> 0.2.0'
1

then pagination should be enabled per Repo (actually it could be completely automated, but I suppose it is done explicitly to have fine control over Monkey Patching)

/config/initializers/enable_pagination.rb

PostRepository.enable_pagination!
UserRepository.enable_pagination!
#...
1
2
3

after that you can get paginated result

 relation = PostRepository.new.filter_somehow(by: param)
 paginated_realtion = relation.per_page(params[:per_page]).page(params[:page])
 # get Pager object
 pager = Hanami::Pagination::Pager.new(paginated_realtion.pager)
 # and query results
 posts = paginated_realtion.to_a
1
2
3
4
5
6

Now pager variable has a lot of useful info like total, current_page, etc.

TODO: add link to 'hanami-pagination' gem docs

# Using Pagy gem

TODO: Investigate and try http://katafrakt.me/2018/06/01/integrating-pagy-with-hanami/