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 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
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
61 62 63 64 |
# File 'lib/cequel/metal/updater.rb', line 61 def list_append(column, 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 |
# File 'lib/cequel/metal/updater.rb', line 47 def list_prepend(column, 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
75 76 77 78 |
# File 'lib/cequel/metal/updater.rb', line 75 def list_remove(column, 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
90 91 92 93 |
# File 'lib/cequel/metal/updater.rb', line 90 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
132 133 134 135 136 |
# File 'lib/cequel/metal/updater.rb', line 132 def map_update(column, updates) binding_pairs = ::Array.new(updates.length) { '?:?' }.join(',') statements << "#{column} = #{column} + {#{binding_pairs}}" bind_vars.concat(updates.flatten) 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
104 105 106 107 |
# File 'lib/cequel/metal/updater.rb', line 104 def set_add(column, values) statements << "#{column} = #{column} + {?}" bind_vars << values end |
#set_remove(column, values) ⇒ void
This method returns an undefined value.
Remove elements from a set
118 119 120 121 |
# File 'lib/cequel/metal/updater.rb', line 118 def set_remove(column, values) statements << "#{column} = #{column} - {?}" bind_vars << ::Kernel.Array(values) end |