Class: Believer::BatchDelete

Inherits:
FilterCommand show all
Defined in:
lib/believer/batch_delete.rb

Constant Summary collapse

DELETE_BATCH_CHUNK_SIZE =
100

Instance Attribute Summary

Attributes inherited from Command

#consistency_level, #record_class

Instance Method Summary collapse

Methods inherited from FilterCommand

#query_attributes, #where, #wheres, #wheres=

Methods inherited from Command

#can_execute?, #clone, #command_name, #consistency, #execution_options, #execution_options=, #initialize, #override_execution_options, #query_attributes

Constructor Details

This class inherits a constructor from Believer::Command

Instance Method Details

#executeObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/believer/batch_delete.rb', line 6

def execute
  #cql = "DELETE FROM #{@record_class.table_name}"
  #cql << " WHERE #{@wheres.map { |wc| "#{wc.to_cql}" }.join(' AND ')}" if @wheres && @wheres.any?
  #cql << " #{@limit_to.to_cql}" unless @limit_to.nil?
  #cql

  cnt = count
  s = self.limit_to.size
  key_cols = self.record_class.primary_key_columns
  cql = "BEGIN BATCH\n"
  rows = clone.select(self.record_class.primary_key_columns).execute
  rows.each do |row_to_delete|
    d = Delete.new(:record_class => self.record_class).where(row_to_delete)
    cql += "#{d.to_cql}"
  end
  cql = "APPLY BATCH;\n"
  #BatchDelete.new(:record_class => self.record_class, :wheres => self.wheres, :limit_to => self.limit_to).execute
  cnt
end