Module: CassandraObject::Batches::ClassMethods

Defined in:
lib/cassandra_object/batches.rb

Instance Method Summary collapse

Instance Method Details

#find_eachObject



6
7
8
9
10
# File 'lib/cassandra_object/batches.rb', line 6

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

#find_in_batches(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cassandra_object/batches.rb', line 12

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