Module: InventoryRefresh::SaveCollection::Saver::SqlHelper
- Extended by:
- ActiveSupport::Concern
- Includes:
- Logging
- Included in:
- Base
- Defined in:
- lib/inventory_refresh/save_collection/saver/sql_helper.rb
Instance Method Summary collapse
-
#build_multi_selection_query(hashes) ⇒ String
Builds a multiselection conditions like (table1.a = a1 AND table2.b = b1) OR (table1.a = a2 AND table2.b = b2).
-
#get_connection ⇒ ActiveRecord::ConnectionAdapters::AbstractAdapter
ActiveRecord connection.
-
#pg_type_cast(value, sql_type) ⇒ String
Returns a type casted value in format needed by PostgreSQL.
-
#quote(connection, value, name = nil, type_cast_for_pg = nil) ⇒ String
Quotes a value.
-
#quote_and_pg_type_cast(connection, value, name) ⇒ String
Quotes and type casts the value.
-
#quote_column_name(key) ⇒ Object
Returns quoted column name.
Methods included from Logging
Instance Method Details
#build_multi_selection_query(hashes) ⇒ String
Builds a multiselection conditions like (table1.a = a1 AND table2.b = b1) OR (table1.a = a2 AND table2.b = b2)
34 35 36 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper.rb', line 34 def build_multi_selection_query(hashes) inventory_collection.build_multi_selection_condition(hashes, unique_index_columns) end |
#get_connection ⇒ ActiveRecord::ConnectionAdapters::AbstractAdapter
Returns ActiveRecord connection.
26 27 28 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper.rb', line 26 def get_connection ActiveRecord::Base.connection end |
#pg_type_cast(value, sql_type) ⇒ String
Returns a type casted value in format needed by PostgreSQL
76 77 78 79 80 81 82 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper.rb', line 76 def pg_type_cast(value, sql_type) if sql_type.nil? value else "#{value}::#{sql_type}" end end |
#quote(connection, value, name = nil, type_cast_for_pg = nil) ⇒ String
Quotes a value. For update query, the value also needs to be explicitly casted, which we can do by type_cast_for_pg param set to true.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper.rb', line 46 def quote(connection, value, name = nil, type_cast_for_pg = nil) # TODO(lsmola) needed only because UPDATE FROM VALUES needs a specific PG typecasting, remove when fixed in PG if type_cast_for_pg quote_and_pg_type_cast(connection, value, name) else connection.quote(value) end rescue TypeError => e logger.error("Can't quote value: #{value}, of :#{name} and #{inventory_collection}") raise e end |
#quote_and_pg_type_cast(connection, value, name) ⇒ String
Quotes and type casts the value.
64 65 66 67 68 69 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper.rb', line 64 def quote_and_pg_type_cast(connection, value, name) pg_type_cast( connection.quote(value), pg_types[name] ) end |
#quote_column_name(key) ⇒ Object
Returns quoted column name
21 22 23 |
# File 'lib/inventory_refresh/save_collection/saver/sql_helper.rb', line 21 def quote_column_name(key) get_connection.quote_column_name(key) end |