Class: NoSE::Backend::CassandraBackend::DeleteStatementStep

Inherits:
Backend::DeleteStatementStep show all
Defined in:
lib/nose/backend/cassandra.rb

Overview

Delete data from an index on the backend

Instance Attribute Summary

Attributes inherited from Backend::StatementStep

#index

Instance Method Summary collapse

Methods included from Supertype

included

Constructor Details

#initialize(client, index) ⇒ DeleteStatementStep

Returns a new instance of DeleteStatementStep.



234
235
236
237
238
239
240
241
242
243
# File 'lib/nose/backend/cassandra.rb', line 234

def initialize(client, index)
  super

  @index_keys = @index.hash_fields + @index.order_fields.to_set

  # Prepare the statement required to perform the deletion
  delete = "DELETE FROM #{index.key} WHERE "
  delete += @index_keys.map { |key| "\"#{key.id}\" = ?" }.join(' AND ')
  @prepared = client.prepare delete
end

Instance Method Details

#process(results) ⇒ Object

Execute the delete for a given set of keys



246
247
248
249
250
251
252
# File 'lib/nose/backend/cassandra.rb', line 246

def process(results)
  # Delete each row from the index
  results.each do |result|
    values = delete_values result
    @client.execute(@prepared, arguments: values)
  end
end