Skip to content

tapgiants/paginator_tg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PaginatorTG

An wrapper around Paginator. Decorates the result returned from the Paginator by following the Tap Giants data conventions. All provided functions from the Paginator package are available via PaginatorTG package.

Documentation

Installation

The package can be installed by adding paginator_tg to your list of dependencies in mix.exs:

def deps do
  [
    {:paginator_tg, "~> 0.1.1"}
  ]
end

Usage

  1. Add PaginatorTG to your repo.
  defmodule MyApp.Repo do
    use Ecto.Repo,
        otp_app: :my_app,
        adapter: Ecto.Adapters.Postgres

    use PaginatorTG
  end
  1. Use the paginate_tg/2 function to paginate your queries.
  ## Simple example
  query = from(ind in Industry, order_by: [desc: ind.inserted_at, desc: ind.id])

  %{
    list: list,
    total_count: total_count,
    page_info: %{
      start_cursor: start_cursor,
      end_cursor: end_cursor,
      has_next_page: _has_next_page,
      has_previous_page: _has_previous_page,
    }
  } = Repo.paginate_tg(query, cursor_fields: [:inserted_at, :id], first: 30)

  ## Example with cursors

    query = from(ind in Industry, order_by: [desc: ind.inserted_at, desc: ind.id])
    %{
      list: list,
      total_count: total_count,
      page_info: %{
        start_cursor: start_cursor,
        end_cursor: end_cursor,
        has_next_page: _has_next_page,
        has_previous_page: _has_previous_page,
      }
    } = Repo.paginate_tg(query, cursor_fields: [:inserted_at, :id], first: 30)

    query = from(ind in Industry, order_by: [desc: ind.inserted_at, desc: ind.id])
    Repo.paginate_tg(
      query,
      after: end_cursor,
      first: 30,
      cursor_fields: [:inserted_at, :id]
    )

TODOs

  • Better documentation
  • Development section
  • License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages