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 Attribute Summary

Attributes inherited from Writer

#type_hints

Instance Method Summary collapse

Methods included from Util::Forwardable

#delegate

Constructor Details

#initialize(data_set) ⇒ Inserter

Returns a new instance of Inserter.

Parameters:

  • data_set (DataSet)

    data set to write to

Since:

  • 1.0.0



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

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

Instance Method Details

#execute(options = {}) ⇒ void

This method returns an undefined value.

Execute the statement as a write operation

Parameters:

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

    options

Options Hash (options):

  • :consistency (Symbol)

    what consistency level to use for the operation

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



22
23
24
25
26
27
28
29
# File 'lib/cequel/metal/inserter.rb', line 22

def execute(options = {})
  statement = Statement.new
  consistency = options.fetch(:consistency, data_set.query_consistency)
  write_to_statement(statement, options)
  data_set.write_with_options(statement,
                              consistency: consistency
                             )
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



37
38
39
# File 'lib/cequel/metal/inserter.rb', line 37

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