Class: Cql::Client::Batch

  • Object
show all
Defined in:


Batches let you send multiple queries (INSERT, UPDATE and DELETE) in one go. This can lead to better performance, and depending on the options you specify can also give you different consistency guarantees.

Batches can contain a mix of different queries and prepared statements.

See Also:

Instance Method Summary collapse

Instance Method Details

#add(cql_or_prepared_statement, *bound_values) ⇒ nil

Add a query or a prepared statement to the batch.


Adding a mix of statements to a batch

batch.add(%(UPDATE people SET name = 'Miriam' WHERE id = 3435))
batch.add(%(UPDATE people SET name = ? WHERE id = ?), 'Miriam', 3435)
batch.add(prepared_statement, 'Miriam', 3435)


  • cql_or_prepared_statement (String, Cql::Client::PreparedStatement)

    a CQL string or a prepared statement object (obtained through Client#prepare)

  • bound_values (Array)

    a list of bound values -- only applies when adding prepared statements and when there are binding markers in the given CQL. If the last argument is a hash and it has the key :type_hints this will be passed as type hints to the request encoder (if the last argument is any other hash it will be assumed to be a bound value of type MAP). See Client#execute for more info on type hints.


  • (nil)

# File 'lib/cql/client/batch.rb', line 13

#execute(options = {}) ⇒ Cql::Client::VoidResult

Execute the batch and return the result.


  • options (Hash) (defaults to: {})

    an options hash or a symbol (as a shortcut for specifying the consistency), see Client#execute for full details about how this value is interpreted.



  • (Cql::QueryError)

    raised when there is an error on the server side

  • (Cql::NotPreparedError)

    raised in the unlikely event that a prepared statement was not prepared on the chosen connection

# File 'lib/cql/client/batch.rb', line 45