Class: Cequel::Metal::Inserter

Inherits:
Writer
  • Object
show all
Defined in:
lib/cequel/metal/inserter.rb

Overview

Encapsulates an ‘INSERT` statement

See Also:

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

#initialize(data_set, options = {}) ⇒ Inserter

Returns a new instance of Inserter.

Parameters:

  • data_set (DataSet)

    data set to write to

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

    options

Options Hash (options):

  • :ttl (Integer)

    time-to-live in seconds for the written data

  • :timestamp (Time, Integer)

    the timestamp associated with the column values

Since:

  • 1.0.0



13
14
15
16
# File 'lib/cequel/metal/inserter.rb', line 13

def initialize(data_set, options = {})
  @row = {}
  super
end

Instance Method Details

#executevoid

This method returns an undefined value.

Execute the statement as a write operation

Since:

  • 1.0.0



21
22
23
24
25
# File 'lib/cequel/metal/inserter.rb', line 21

def execute
  statement = Statement.new
  write_to_statement(statement)
  data_set.write(*statement.args)
end

#insert(data) ⇒ void

This method returns an undefined value.

Insert the given data into the table

Parameters:

  • data (Hash<Symbol,Object>)

    map of column names to values

Since:

  • 1.0.0



33
34
35
# File 'lib/cequel/metal/inserter.rb', line 33

def insert(data)
  @row.merge!(data.symbolize_keys)
end