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.
190 191 192 |
# File 'lib/active_record/insert_all.rb', line 190 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.
186 187 188 |
# File 'lib/active_record/insert_all.rb', line 186 def model @model end |
Instance Method Details
#conflict_target ⇒ Object
219 220 221 222 223 224 225 226 227 |
# File 'lib/active_record/insert_all.rb', line 219 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
194 195 196 |
# File 'lib/active_record/insert_all.rb', line 194 def into "INTO #{model.quoted_table_name} (#{columns_list})" end |
#raw_update_sql ⇒ Object Also known as: raw_update_sql?
243 244 245 |
# File 'lib/active_record/insert_all.rb', line 243 def raw_update_sql insert_all.update_sql end |
#returning ⇒ Object
209 210 211 212 213 214 215 216 217 |
# File 'lib/active_record/insert_all.rb', line 209 def returning return unless insert_all.returning if insert_all.returning.is_a?(String) insert_all.returning else format_columns(insert_all.returning) end end |
#touch_model_timestamps_unless(&block) ⇒ Object
233 234 235 236 237 238 239 240 241 |
# File 'lib/active_record/insert_all.rb', line 233 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
229 230 231 |
# File 'lib/active_record/insert_all.rb', line 229 def updatable_columns quote_columns(insert_all.updatable_columns) end |
#values_list ⇒ Object
198 199 200 201 202 203 204 205 206 207 |
# File 'lib/active_record/insert_all.rb', line 198 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 connection.with_yaml_fallback(types[key].serialize(value)) end connection.visitor.compile(Arel::Nodes::ValuesList.new(values_list)) end |