Module: InventoryRefresh::SaveCollection::Saver::SqlHelperUpdate
- Includes:
- Logging
- Defined in:
- lib/inventory_refresh/save_collection/saver/sql_helper_update.rb
Instance Method Summary collapse
-
#build_partial_update_query(all_attribute_keys, hashes) ⇒ Object
Build batch update query only for passed all_attribute_keys.
-
#build_update_query(all_attribute_keys, hashes) ⇒ Object
Build batch update query.
-
#build_update_set_cols(key) ⇒ String
Builds update clause for one column identified by the passed key.
Methods included from Logging
Instance Method Details
#build_partial_update_query(all_attribute_keys, hashes) ⇒ Object
Build batch update query only for passed all_attribute_keys
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper_update.rb', line 51 def build_partial_update_query(all_attribute_keys, hashes) # Cache the connection for the batch connection = get_connection all_attribute_keys = (all_attribute_keys + unique_index_columns).uniq update_query = update_query_beginning(all_attribute_keys) update_query += update_query_from_values(hashes, all_attribute_keys, connection, unique_index_columns) update_query end |
#build_update_query(all_attribute_keys, hashes) ⇒ Object
Build batch update query
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper_update.rb', line 20 def build_update_query(all_attribute_keys, hashes) logger.debug("Building update query for #{inventory_collection} of size #{inventory_collection.size}...") # Cache the connection for the batch connection = get_connection # We want to ignore create timestamps when updating all_attribute_keys_array = all_attribute_keys.to_a.delete_if { |x| %i[created_at created_on].include?(x) } all_attribute_keys_array << :id # If there is not version attribute, the version conditions will be ignored version_attribute = if inventory_collection.parallel_safe? && (all_attribute_keys) :resource_timestamp elsif inventory_collection.parallel_safe? && supports_remote_data_version?(all_attribute_keys) :resource_counter end update_query = update_query_beginning(all_attribute_keys_array) update_query += update_query_reset_version_columns(version_attribute) update_query += update_query_from_values(hashes, all_attribute_keys_array, connection) update_query += update_query_version_conditions(version_attribute) update_query += update_query_returning logger.debug("Building update query for #{inventory_collection} of size #{inventory_collection.size}...Complete") update_query end |
#build_update_set_cols(key) ⇒ String
Builds update clause for one column identified by the passed key
12 13 14 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper_update.rb', line 12 def build_update_set_cols(key) "#{quote_column_name(key)} = updated_values.#{quote_column_name(key)}" end |