Class: Cassandra::Statements::Batch

Inherits:
Object
  • Object
show all
Includes:
Cassandra::Statement
Defined in:
lib/cassandra/statements/batch.rb

Overview

Batch statement groups several Cassandra::Statement. There are several types of Batch statements available:

Instance Method Summary collapse

Instance Method Details

#add(statement, options = nil) ⇒ self

Note:

Positional arguments for simple statements are only supported starting with Apache Cassandra 2.0 and above.

Note:

Named arguments for simple statements are only supported starting with Apache Cassandra 2.1 and above.

Adds a statement to this batch.

Parameters:

Options Hash (options):

  • :arguments (Array, Hash) — default: nil

    positional or named arguments to bind, must contain the same number of parameters as the number of positional (?) or named (:name) markers in the CQL passed.

  • :type_hints (Array, Hash) — default: nil

    override Util.guess_type to determine the CQL type for an argument; nil elements will fall-back to Util.guess_type.

  • :idempotent (Boolean) — default: false

    specify whether this statement can be retried safely on timeout.

Returns:

  • (self)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cassandra/statements/batch.rb', line 90

def add(statement, options = nil)
  options = if options.is_a?(::Hash)
              @options.override(options)
            else
              @options
            end

  case statement
  when String
    @statements << Simple.new(statement,
                              options.arguments,
                              options.type_hints,
                              options.idempotent?)
  when Prepared
    @statements << statement.bind(options.arguments)
  when Bound, Simple
    @statements << statement
  else
    raise ::ArgumentError,
          'a batch can only consist of simple or prepared statements, ' \
              "#{statement.inspect} given"
  end

  self
end

#cqlnil

A batch statement doesn't really have any cql of its own as it is composed of multiple different statements

Returns:

  • (nil)

    nothing



132
133
134
# File 'lib/cassandra/statements/batch.rb', line 132

def cql
  nil
end

#idempotent?Boolean

Determines whether or not the statement is safe to retry on timeout Batches are idempotent only when all statements in a batch are.

Returns:

  • (Boolean)

    whether the statement is safe to retry on timeout



125
126
127
# File 'lib/cassandra/statements/batch.rb', line 125

def idempotent?
  @statements.all?(&:idempotent?)
end

#inspectString

Returns a CLI-friendly batch statement representation.

Returns:

  • (String)

    a CLI-friendly batch statement representation



141
142
143
# File 'lib/cassandra/statements/batch.rb', line 141

def inspect
  "#<#{self.class.name}:0x#{object_id.to_s(16)} @type=#{type.inspect}>"
end

#typeSymbol

Returns one of :logged, :unlogged or :counter.

Returns:

  • (Symbol)

    one of :logged, :unlogged or :counter



137
138
# File 'lib/cassandra/statements/batch.rb', line 137

def type
end