Class: Believer::Batch

Inherits:
Command show all
Defined in:
lib/believer/batch.rb

Overview

A command which issues 0 or more other commands in batch to the Cassandra server. This is achieved using the CQL BATCH command

Instance Attribute Summary

Attributes inherited from Command

#consistency_level, #record_class

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

This class inherits a constructor from Believer::Command

Instance Method Details

#<<(command) ⇒ Object

Adds a command

Parameters:



15
16
17
# File 'lib/believer/batch.rb', line 15

def <<(command)
  add(command)
end

#add(command) ⇒ Object

Adds a command

Parameters:



21
22
23
24
# File 'lib/believer/batch.rb', line 21

def add(command)
  commands << command
  self
end

#commandsArray<Command>

Yields the collection of commands

Returns:

  • (Array<Command>)

    the command collection



9
10
11
# File 'lib/believer/batch.rb', line 9

def commands
  @commands ||= []
end

#to_cqlString

Yields the CQL for this command

Returns:

  • (String)

    the CQL



28
29
30
31
32
33
34
35
# File 'lib/believer/batch.rb', line 28

def to_cql
  cql = "BEGIN BATCH\n"
  commands.each do |c|
    cql += "  #{c.to_cql}\n"
  end
  cql += "APPLY BATCH;\n"
  cql
end