Class: Arel::InsertManager

Inherits:
TreeManager show all
Defined in:
lib/arel/insert_manager.rb

Instance Attribute Summary

Attributes inherited from TreeManager

#ast, #bind_values, #engine

Instance Method Summary (collapse)

Methods inherited from TreeManager

#initialize_copy, #to_dot, #to_sql, #visitor, #where

Methods included from FactoryMethods

#create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, #lower

Constructor Details

- (InsertManager) initialize(engine)

Returns a new instance of InsertManager



3
4
5
6
# File 'lib/arel/insert_manager.rb', line 3

def initialize engine
  super
  @ast = Nodes::InsertStatement.new
end

Instance Method Details

- (Object) columns



13
# File 'lib/arel/insert_manager.rb', line 13

def columns; @ast.columns end

- (Object) create_values(values, columns)



34
35
36
# File 'lib/arel/insert_manager.rb', line 34

def create_values values, columns
  Nodes::Values.new values, columns
end

- (Object) insert(fields)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/arel/insert_manager.rb', line 16

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, @ast.columns
  end
end

- (Object) into(table)



8
9
10
11
# File 'lib/arel/insert_manager.rb', line 8

def into table
  @ast.relation = table
  self
end

- (Object) values=(val)



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

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