Sha256: 55115d3de98061110c9986bf35c4d2b32fbb808d5f95698314ca96b591f6f057

Contents?: true

Size: 667 Bytes

Versions: 4

Compression:

Stored size: 667 Bytes

Contents

module CassandraObject
  module Batches
    extend ActiveSupport::Concern

    module ClassMethods
      def find_each
        connection.each(column_family) do |k, v|
          yield instantiate(k, v)
        end
      end

      def find_in_batches(options = {})
        batch_size = options.delete(:batch_size) || 1000

        batch = []

        find_each do |record|
          batch << record
          if batch.size == batch_size
            yield(batch)
            batch = []
          end
        end

        if batch.size > 0
          yield batch
        end
      end

      def batch(&block)
        connection.batch(&block)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.8.3 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.8.2 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.8.1 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.8.0 lib/cassandra_object/batches.rb