Class: Arel::InsertManager
Instance Attribute Summary
Attributes inherited from TreeManager
#ast
Instance Method Summary
collapse
Methods inherited from TreeManager
#initialize_copy, #to_dot, #to_sql, #where
#coalesce, #create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, #lower
Constructor Details
Returns a new instance of InsertManager.
5
6
7
8
|
# File 'activerecord/lib/arel/insert_manager.rb', line 5
def initialize
super
@ast = Nodes::InsertStatement.new
end
|
Instance Method Details
15
|
# File 'activerecord/lib/arel/insert_manager.rb', line 15
def columns; @ast.columns end
|
#create_values(values) ⇒ Object
41
42
43
|
# File 'activerecord/lib/arel/insert_manager.rb', line 41
def create_values(values)
Nodes::ValuesList.new([values])
end
|
#create_values_list(rows) ⇒ Object
45
46
47
|
# File 'activerecord/lib/arel/insert_manager.rb', line 45
def create_values_list(rows)
Nodes::ValuesList.new(rows)
end
|
#insert(fields) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'activerecord/lib/arel/insert_manager.rb', line 22
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) ⇒ Object
10
11
12
13
|
# File 'activerecord/lib/arel/insert_manager.rb', line 10
def into(table)
@ast.relation = table
self
end
|
#select(select) ⇒ Object
18
19
20
|
# File 'activerecord/lib/arel/insert_manager.rb', line 18
def select(select)
@ast.select = select
end
|
#values=(val) ⇒ Object
16
|
# File 'activerecord/lib/arel/insert_manager.rb', line 16
def values=(val); @ast.values = val; end
|