Sha256: 5f467efc4e9bc6ce6ea0431197787561ea54feb50800314637a450eb8406dfa5

Contents?: true

Size: 994 Bytes

Versions: 2

Compression:

Stored size: 994 Bytes

Contents

# frozen_string_literal: true

module Ductr
  module SequelBase
    #
    # A source control that allows to select a big number of rows by relying on pagination.
    #
    class PaginatedSource < Ductr::ETL::PaginatedSource
      #
      # Calls the job's method and iterate on the query result.
      # Returns true if the page is full, false otherwise.
      #
      # @yield The each block
      #
      # @raise [InconsistentPaginationError] When the query return more rows than the page size
      # @return [Boolean] True if the page is full, false otherwise.
      #
      def each_page(&)
        rows_count = 0

        call_method(adapter.db, @offset, page_size).each do |row|
          yield(row)
          rows_count += 1
        end

        if rows_count > page_size
          raise InconsistentPaginationError,
                "The query returned #{rows_count} rows but the page size is #{page_size} rows"
        end

        rows_count == page_size
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ductr-0.2.3 lib/ductr/sequel_base/paginated_source.rb
ductr-0.2.2 lib/ductr/sequel_base/paginated_source.rb