Sha256: ef1ab9f8641b4024a42fe99f053d804af7a14d290864954c4a09d42a2f214800

Contents?: true

Size: 679 Bytes

Versions: 17

Compression:

Stored size: 679 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

17 entries across 17 versions & 1 rubygems

Version Path
gotime-cassandra_object-3.0.5 lib/cassandra_object/batches.rb
gotime-cassandra_object-3.0.4 lib/cassandra_object/batches.rb
gotime-cassandra_object-3.0.3 lib/cassandra_object/batches.rb
gotime-cassandra_object-3.0.2 lib/cassandra_object/batches.rb
gotime-cassandra_object-3.0.1 lib/cassandra_object/batches.rb
gotime-cassandra_object-3.0.0 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.13.0 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.12.5 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.12.4 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.12.3 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.12.2 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.12.1 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.12.0 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.9 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.8 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.7 lib/cassandra_object/batches.rb
gotime-cassandra_object-2.11.6 lib/cassandra_object/batches.rb