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.11.5 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.4 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.3 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.2 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.1 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.0 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.11 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.10 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.9 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.8 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.7 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.6 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.5 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.4 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.3 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.2 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.1 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.10.0 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.9.2 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.9.1 lib/cassandra_object/batches.rb