Sha256: 168310310b42830d52e2f1f52289b45ef5c6f0b7dde04acfd2ee7a1cec5a08fa

Contents?: true

Size: 791 Bytes

Versions: 2

Compression:

Stored size: 791 Bytes

Contents

require "metacrunch/db"

module Metacrunch
  class Db::Reader

    def initialize(database_connection_or_url, dataset_proc, options = {})
      @rows_per_fetch = options.delete(:rows_per_fetch) || 1000

      @db = if database_connection_or_url.is_a?(String)
        Sequel.connect(database_connection_or_url, options)
      else
        database_connection_or_url
      end

      @dataset = dataset_proc.call(@db).unlimited

      unless @dataset.opts[:order]
        raise ArgumentError, "Metacrunch::Db::Reader requires the dataset be ordered."
      end
    end

    def each(&block)
      return enum_for(__method__) unless block_given?

      @dataset.paged_each(rows_per_fetch: @rows_per_fetch, strategy: :filter) do |row|
        yield(row)
      end

      self
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metacrunch-3.1.4 lib/metacrunch/db/reader.rb
metacrunch-3.1.3 lib/metacrunch/db/reader.rb