Module: InventoryRefresh::SaveCollection::Saver::SqlHelperUpsert
- Includes:
- Logging
- Defined in:
- lib/inventory_refresh/save_collection/saver/sql_helper_upsert.rb
Instance Method Summary collapse
- #build_insert_query(all_attribute_keys, hashes, on_conflict: nil, mode:, column_name: nil) ⇒ Object
-
#build_insert_set_cols(key) ⇒ String
Builds ON CONFLICT UPDATE updating branch for one column identified by the passed key.
Methods included from Logging
Instance Method Details
#build_insert_query(all_attribute_keys, hashes, on_conflict: nil, mode:, column_name: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper_upsert.rb', line 22 def build_insert_query(all_attribute_keys, hashes, on_conflict: nil, mode:, column_name: nil) logger.debug("Building insert query for #{inventory_collection} of size #{inventory_collection.size}...") # Cache the connection for the batch connection = get_connection # Ignore versioning columns that are set separately ignore_cols = mode == :partial ? [:resource_timestamp, :resource_counter] : [] # Make sure we don't send a primary_key for INSERT in any form, it could break PG sequencer all_attribute_keys_array = all_attribute_keys.to_a - [primary_key.to_s, primary_key.to_sym] - ignore_cols insert_query = insert_query_insert_values(hashes, all_attribute_keys_array, connection) insert_query += insert_query_on_conflict_behavior(all_attribute_keys, on_conflict, mode, ignore_cols, column_name) insert_query += insert_query_returning logger.debug("Building insert query for #{inventory_collection} of size #{inventory_collection.size}...Complete") insert_query end |
#build_insert_set_cols(key) ⇒ String
Builds ON CONFLICT UPDATE updating branch for one column identified by the passed key
12 13 14 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper_upsert.rb', line 12 def build_insert_set_cols(key) "#{quote_column_name(key)} = EXCLUDED.#{quote_column_name(key)}" end |