Class: Cequel::Batch
- Inherits:
-
Object
- Object
- Cequel::Batch
- Defined in:
- lib/cequel/batch.rb
Overview
Encapsulates a batch operation
Instance Method Summary collapse
-
#apply ⇒ Object
Send the batch to Cassandra.
-
#execute(cql, *bind_vars) ⇒ Object
Add a statement to the batch.
-
#initialize(keyspace, options = {}) ⇒ Batch
constructor
A new instance of Batch.
Constructor Details
#initialize(keyspace, options = {}) ⇒ Batch
TODO:
support batch-level consistency options
Returns a new instance of Batch.
19 20 21 22 23 |
# File 'lib/cequel/batch.rb', line 19 def initialize(keyspace, = {}) @keyspace = keyspace @auto_apply = [:auto_apply] reset end |
Instance Method Details
#apply ⇒ Object
Send the batch to Cassandra
42 43 44 45 46 |
# File 'lib/cequel/batch.rb', line 42 def apply return if @statement_count.zero? @statement.append("APPLY BATCH\n") @keyspace.execute(*@statement.args) end |
#execute(cql, *bind_vars) ⇒ Object
Add a statement to the batch.
30 31 32 33 34 35 36 37 |
# File 'lib/cequel/batch.rb', line 30 def execute(cql, *bind_vars) @statement.append("#{cql}\n", *bind_vars) @statement_count += 1 if @auto_apply && @statement_count >= @auto_apply apply reset end end |