Class: NoSE::Backend::FileBackend::InsertStatementStep
- Inherits:
-
Backend::InsertStatementStep
- Object
- Backend::StatementStep
- Backend::InsertStatementStep
- NoSE::Backend::FileBackend::InsertStatementStep
- Defined in:
- lib/nose/backend/file.rb
Overview
Insert data into an index on the backend
Instance Attribute Summary
Attributes inherited from Backend::StatementStep
Instance Method Summary collapse
-
#process(results) ⇒ Object
Add new rows to the index.
Methods inherited from Backend::InsertStatementStep
Methods included from Supertype
Constructor Details
This class inherits a constructor from NoSE::Backend::Backend::InsertStatementStep
Instance Method Details
#process(results) ⇒ Object
Add new rows to the index
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/nose/backend/file.rb', line 135 def process(results) key_ids = (@index.hash_fields + @index.order_fields).map(&:id).to_set results.each do |row| # Pick out primary key fields we can use to match conditions = row.select do |field_id| key_ids.include? field_id end # If we have all the primary keys, check for a match if conditions.length == key_ids.length # Try to find a row with this ID and update it matching_row = @client[index.key].find do |index_row| index_row.merge(conditions) == index_row end unless matching_row.nil? matching_row.merge! row next end end # Populate IDs as needed key_ids.each do |key_id| row[key_id] = SecureRandom.uuid if row[key_id].nil? end @client[index.key] << row end end |