Class: InsertSelect::ActiveRecord::InsertSelectFrom
- Inherits:
-
Object
- Object
- InsertSelect::ActiveRecord::InsertSelectFrom
- Defined in:
- lib/insert_select/active_record.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#on_duplicate ⇒ Object
readonly
Returns the value of attribute on_duplicate.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
-
#returning ⇒ Object
readonly
Returns the value of attribute returning.
Instance Method Summary collapse
- #builder ⇒ Object
- #ensure_valid_options_for_connection! ⇒ Object
- #execute ⇒ Object
-
#initialize(model, relation, mapping:, on_duplicate:, returning: nil) ⇒ InsertSelectFrom
constructor
A new instance of InsertSelectFrom.
- #to_sql ⇒ Object
Constructor Details
#initialize(model, relation, mapping:, on_duplicate:, returning: nil) ⇒ InsertSelectFrom
Returns a new instance of InsertSelectFrom.
53 54 55 56 57 58 59 60 61 |
# File 'lib/insert_select/active_record.rb', line 53 def initialize(model, relation, mapping:, on_duplicate:, returning: nil) @model = model @connection = model.connection @relation = relation @adapter = find_adapter(connection) @mapping = mapping @returning = returning @on_duplicate = on_duplicate end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
51 52 53 |
# File 'lib/insert_select/active_record.rb', line 51 def adapter @adapter end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
51 52 53 |
# File 'lib/insert_select/active_record.rb', line 51 def connection @connection end |
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
51 52 53 |
# File 'lib/insert_select/active_record.rb', line 51 def mapping @mapping end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
51 52 53 |
# File 'lib/insert_select/active_record.rb', line 51 def model @model end |
#on_duplicate ⇒ Object (readonly)
Returns the value of attribute on_duplicate.
51 52 53 |
# File 'lib/insert_select/active_record.rb', line 51 def on_duplicate @on_duplicate end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
51 52 53 |
# File 'lib/insert_select/active_record.rb', line 51 def relation @relation end |
#returning ⇒ Object (readonly)
Returns the value of attribute returning.
51 52 53 |
# File 'lib/insert_select/active_record.rb', line 51 def returning @returning end |
Instance Method Details
#builder ⇒ Object
72 73 74 |
# File 'lib/insert_select/active_record.rb', line 72 def builder @builder ||= Builder.new(self) end |
#ensure_valid_options_for_connection! ⇒ Object
76 77 78 79 80 |
# File 'lib/insert_select/active_record.rb', line 76 def if returning && !connection.supports_insert_returning? raise ArgumentError, "#{connection.class} does not support :returning" end end |
#execute ⇒ Object
63 64 65 66 |
# File 'lib/insert_select/active_record.rb', line 63 def execute sql = model.sanitize_sql_array([to_sql, *builder.constant_values]) connection.exec_insert_all(sql, "Bulk Insert") end |
#to_sql ⇒ Object
68 69 70 |
# File 'lib/insert_select/active_record.rb', line 68 def to_sql @to_sql ||= adapter.build_sql(builder) end |