Class: Cequel::Metal::Updater

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

Overview

Builder for ‘UPDATE` statement containing heterogeneous operations (set columns, atomically mutate collections)

Instance Attribute Summary

Attributes inherited from Writer

#type_hints

Instance Method Summary collapse

Methods inherited from Writer

#execute

Methods included from Util::Forwardable

#delegate

Constructor Details

#initializeUpdater

Returns a new instance of Updater.

See Also:

Since:

  • 1.0.0



19
20
21
22
# File 'lib/cequel/metal/updater.rb', line 19

def initialize(*)
  @column_updates = {}
  super
end

Instance Method Details

#list_append(column, elements) ⇒ void

This method returns an undefined value.

Append elements to a list column

Parameters:

  • column (Symbol)

    column name

  • elements (Array)

    elements to append

See Also:

Since:

  • 1.0.0



62
63
64
65
66
# File 'lib/cequel/metal/updater.rb', line 62

def list_append(column, elements)
  elements = Array(elements)
  statements << "#{column} = #{column} + ?"
  bind_vars << elements
end

#list_prepend(column, elements) ⇒ void

This method returns an undefined value.

Prepend elements to a list column

Parameters:

  • column (Symbol)

    column name

  • elements (Array<Object>)

    elements to prepend

See Also:

Since:

  • 1.0.0



47
48
49
50
51
# File 'lib/cequel/metal/updater.rb', line 47

def list_prepend(column, elements)
  elements = Array(elements)
  statements << "#{column} = ? + #{column}"
  bind_vars << elements
end

#list_remove(column, value) ⇒ void

This method returns an undefined value.

Remove all occurrences of an element from a list

Parameters:

  • column (Symbol)

    column name

  • value

    value to remove

See Also:

Since:

  • 1.0.0



77
78
79
80
81
# File 'lib/cequel/metal/updater.rb', line 77

def list_remove(column, value)
  value = Array(value)
  statements << "#{column} = #{column} - ?"
  bind_vars << value
end

#list_replace(column, index, value) ⇒ void

This method returns an undefined value.

Replace a list item at a given position

Parameters:

  • column (Symbol)

    column name

  • index (Integer)

    index at which to replace value

  • value

    new value for position

See Also:

Since:

  • 1.0.0



93
94
95
96
# File 'lib/cequel/metal/updater.rb', line 93

def list_replace(column, index, value)
  statements << "#{column}[#{index}] = ?"
  bind_vars << value
end

#map_update(column, updates) ⇒ void

This method returns an undefined value.

Add or update elements in a map

Parameters:

  • column (Symbol)

    column name

  • updates (Hash)

    map of keys to values to update in map

See Also:

Since:

  • 1.0.0



135
136
137
138
# File 'lib/cequel/metal/updater.rb', line 135

def map_update(column, updates)
  statements << "#{column} = #{column} + ?"
  bind_vars << updates
end

#set(data) ⇒ void

This method returns an undefined value.

Directly set column values

Parameters:

  • data (Hash)

    map of column names to values

See Also:

Since:

  • 1.0.0



32
33
34
35
36
# File 'lib/cequel/metal/updater.rb', line 32

def set(data)
  data.each_pair do |column, value|
    column_updates[column.to_sym] = value
  end
end

#set_add(column, values) ⇒ void

This method returns an undefined value.

Add elements to a set

Parameters:

  • column (Symbol)

    column name

  • values (Set)

    elements to add to set

See Also:

Since:

  • 1.0.0



107
108
109
110
# File 'lib/cequel/metal/updater.rb', line 107

def set_add(column, values)
  statements << "#{column} = #{column} + ?"
  bind_vars << Set.new(::Kernel.Array(values))
end

#set_remove(column, values) ⇒ void

This method returns an undefined value.

Remove elements from a set

Parameters:

  • column (Symbol)

    column name

  • values (Set)

    elements to remove from set

See Also:

Since:

  • 1.0.0



121
122
123
124
# File 'lib/cequel/metal/updater.rb', line 121

def set_remove(column, values)
  statements << "#{column} = #{column} - ?"
  bind_vars << Set.new(::Kernel.Array(values))
end