Class: Cequel::Metal::Updater
- 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
Instance Method Summary collapse
-
#initialize ⇒ Updater
constructor
A new instance of Updater.
-
#list_append(column, elements) ⇒ void
Append elements to a list column.
-
#list_prepend(column, elements) ⇒ void
Prepend elements to a list column.
-
#list_remove(column, value) ⇒ void
Remove all occurrences of an element from a list.
-
#list_replace(column, index, value) ⇒ void
Replace a list item at a given position.
-
#map_update(column, updates) ⇒ void
Add or update elements in a map.
-
#set(data) ⇒ void
Directly set column values.
-
#set_add(column, values) ⇒ void
Add elements to a set.
-
#set_remove(column, values) ⇒ void
Remove elements from a set.
Methods inherited from Writer
Methods included from Util::Forwardable
Constructor Details
#initialize ⇒ Updater
Returns a new instance of Updater.
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
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
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
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
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
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
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
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
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 |