Sha256: abb78fbd0565aab316facab945b93d3f61eb76fafa2d3a59fe0a6fd4ef937ac5

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require_relative 'pagination_handler'

module Praxis
  module Extensions
    module Pagination
      class SequelPaginationHandler < PaginationHandler
        def self.where_lt(query, attr, value)
          query.where("#{attr} < ?", value)
        end

        def self.where_gt(query, attr, value)
          query.where("#{attr} > ?", value)
        end

        def self.order(query, order, _root_resource: nil)
          return query unless order

          order_clause = order.map do |spec_hash|
            direction, name = spec_hash.first
            case direction.to_sym
            when :desc
              Sequel.desc(name.to_sym)
            else
              Sequel.asc(name.to_sym)
            end
          end
          query.order(*order_clause)
        end

        def self.count(query)
          query.count
        end

        def self.offset(query, offset)
          query.offset(offset)
        end

        def self.limit(query, limit)
          query.limit(limit)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
praxis-2.0.0 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.40 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.39 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.38 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.37 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.36 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.35 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.34 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.33 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.32 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.31 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.30 lib/praxis/extensions/pagination/sequel_pagination_handler.rb