1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/arel/insert_manager.rb
2014-02-10 19:44:00 -02:00

38 lines
788 B
Ruby

module Arel
class InsertManager < Arel::TreeManager
def initialize engine
super
@ast = Nodes::InsertStatement.new
end
def into table
@ast.relation = table
self
end
def columns; @ast.columns end
def values= val; @ast.values = val; end
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
def create_values values, columns
Nodes::Values.new values, columns
end
end
end