Class: ActiveRecord::InsertAll::Builder
- Inherits:
-
Object
- Object
- ActiveRecord::InsertAll::Builder
- Defined in:
- lib/active_record/insert_all.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #conflict_target ⇒ Object
-
#initialize(insert_all) ⇒ Builder
constructor
A new instance of Builder.
- #into ⇒ Object
- #raw_update_sql ⇒ Object (also: #raw_update_sql?)
- #returning ⇒ Object
- #touch_model_timestamps_unless(&block) ⇒ Object
- #updatable_columns ⇒ Object
- #values_list ⇒ Object
Constructor Details
#initialize(insert_all) ⇒ Builder
Returns a new instance of Builder.
230 231 232 |
# File 'lib/active_record/insert_all.rb', line 230 def initialize(insert_all) @insert_all, @model, @connection = insert_all, insert_all.model, insert_all.connection end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
226 227 228 |
# File 'lib/active_record/insert_all.rb', line 226 def model @model end |
Instance Method Details
#conflict_target ⇒ Object
265 266 267 268 269 270 271 272 273 |
# File 'lib/active_record/insert_all.rb', line 265 def conflict_target if index = insert_all.unique_by sql = +"(#{format_columns(index.columns)})" sql << " WHERE #{index.where}" if index.where sql elsif update_duplicates? "(#{format_columns(insert_all.primary_keys)})" end end |
#into ⇒ Object
234 235 236 |
# File 'lib/active_record/insert_all.rb', line 234 def into "INTO #{model.quoted_table_name} (#{columns_list})" end |
#raw_update_sql ⇒ Object Also known as: raw_update_sql?
289 290 291 |
# File 'lib/active_record/insert_all.rb', line 289 def raw_update_sql insert_all.update_sql end |
#returning ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/active_record/insert_all.rb', line 249 def returning return unless insert_all.returning if insert_all.returning.is_a?(String) insert_all.returning else Array(insert_all.returning).map do |attribute| if model.attribute_alias?(attribute) "#{quote_column(model.attribute_alias(attribute))} AS #{quote_column(attribute)}" else quote_column(attribute) end end.join(",") end end |
#touch_model_timestamps_unless(&block) ⇒ Object
279 280 281 282 283 284 285 286 287 |
# File 'lib/active_record/insert_all.rb', line 279 def (&block) return "" unless update_duplicates? && model..filter_map do |column_name| if (column_name) "#{column_name}=(CASE WHEN (#{updatable_columns.map(&block).join(" AND ")}) THEN #{model.quoted_table_name}.#{column_name} ELSE #{connection.} END)," end end.join end |
#updatable_columns ⇒ Object
275 276 277 |
# File 'lib/active_record/insert_all.rb', line 275 def updatable_columns quote_columns(insert_all.updatable_columns) end |
#values_list ⇒ Object
238 239 240 241 242 243 244 245 246 247 |
# File 'lib/active_record/insert_all.rb', line 238 def values_list types = extract_types_from_columns_on(model.table_name, keys: ) values_list = insert_all.map_key_with_value do |key, value| next value if Arel::Nodes::SqlLiteral === value types[key].serialize(types[key].cast(value)) end connection.visitor.compile(Arel::Nodes::ValuesList.new(values_list)) end |