Sha256: a7b6cb5f4d2bbb0b22b021e582fa086a2d36c1dbc2d1e687a7033d80ab76f3e4

Contents?: true

Size: 684 Bytes

Versions: 24

Compression:

Stored size: 684 Bytes

Contents

module CassandraObject
  module Batches
    extend ActiveSupport::Concern

    module ClassMethods
      def find_each
        connection.each(column_family, {:count => 500}) 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

24 entries across 24 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.9.0 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.8.6 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.8.5 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.8.4 lib/cassandra_object/batches.rb