Class: Cql::Client::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/cql/client/batch.rb

Overview

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.

Examples:

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)

Parameters:

  • 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.

Returns:

  • (nil)

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

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

Execute the batch and return the result.

Parameters:

  • 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.

Returns:

Raises:

  • (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