class Cequel::Metal::Incrementer

Encapsulates a counter `UPDATE` operation comprising multiple increment or decrement operations

@see DataSet#increment @since 1.0.0

Public Instance Methods

decrement(data) click to toggle source

Decrement one or more columns by given deltas

@param data [Hash<Symbol,Integer>] map of column names to deltas @return [void]

# File lib/cequel/metal/incrementer.rb, line 31
def decrement(data)
  increment(Hash[data.map { |column, count| [column, -count] }])
end
increment(data) click to toggle source

Increment one or more columns by given deltas

@param data [Hash<Symbol,Integer>] map of column names to deltas @return [void]

# File lib/cequel/metal/incrementer.rb, line 17
def increment(data)
  data.each_pair do |column_name, delta|
    operator = delta < 0 ? '-' : '+'
    statements << "#{column_name} = #{column_name} #{operator} ?"
    bind_vars << delta.abs
  end
end

Private Instance Methods

write_to_statement(statement, options) click to toggle source
# File lib/cequel/metal/incrementer.rb, line 37
def write_to_statement(statement, options)
  statement
    .append("UPDATE #{table_name}")
    .append(generate_upsert_options(options))
    .append(
      " SET " << statements.join(', '),
      *bind_vars
  )
end