123456789_123456789_123456789_123456789_123456789_

Class: Arel::InsertManager

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, TreeManager
Instance Chain:
Inherits: Arel::TreeManager
Defined in: activerecord/lib/arel/insert_manager.rb

Class Method Summary

Instance Attribute Summary

TreeManager - Inherited

Instance Method Summary

Constructor Details

.new(table = nil) ⇒ InsertManager

[ GitHub ]

  
# File 'activerecord/lib/arel/insert_manager.rb', line 5

def initialize(table = nil)
  @ast = Nodes::InsertStatement.new(table)
end

Instance Attribute Details

#values=(val) (writeonly)

[ GitHub ]

  
# File 'activerecord/lib/arel/insert_manager.rb', line 15

def values=(val); @ast.values = val; end

Instance Method Details

#columns

[ GitHub ]

  
# File 'activerecord/lib/arel/insert_manager.rb', line 14

def columns; @ast.columns end

#create_values(values)

[ GitHub ]

  
# File 'activerecord/lib/arel/insert_manager.rb', line 40

def create_values(values)
  Nodes::ValuesList.new([values])
end

#create_values_list(rows)

[ GitHub ]

  
# File 'activerecord/lib/arel/insert_manager.rb', line 44

def create_values_list(rows)
  Nodes::ValuesList.new(rows)
end

#insert(fields)

[ GitHub ]

  
# File 'activerecord/lib/arel/insert_manager.rb', line 21

def insert(fields)
  return if fields.empty?

  if String === fields
    @ast.values = Nodes::SqlLiteral.new(fields)
  else
    @ast.relation ||= fields.first.first.relation

    values = []

    fields.each do |column, value|
      @ast.columns << column
      values << value
    end
    @ast.values = create_values(values)
  end
  self
end

#into(table)

[ GitHub ]

  
# File 'activerecord/lib/arel/insert_manager.rb', line 9

def into(table)
  @ast.relation = table
  self
end

#select(select)

[ GitHub ]

  
# File 'activerecord/lib/arel/insert_manager.rb', line 17

def select(select)
  @ast.select = select
end