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

39 lines
788 B
Ruby
Raw Normal View History

module Arel
class InsertManager < Arel::TreeManager
def initialize engine
super
2010-11-05 17:09:09 -04:00
@ast = Nodes::InsertStatement.new
end
def into table
2010-11-05 17:09:09 -04:00
@ast.relation = table
self
end
2010-08-13 18:43:32 -04:00
2010-11-05 17:09:09 -04:00
def columns; @ast.columns end
def values= val; @ast.values = val; end
2010-08-13 21:28:38 -04:00
def insert fields
return if fields.empty?
if String === fields
2014-02-05 15:40:52 -05:00
@ast.values = Nodes::SqlLiteral.new(fields)
else
2010-11-05 17:09:09 -04:00
@ast.relation ||= fields.first.first.relation
2010-08-13 21:28:38 -04:00
values = []
fields.each do |column, value|
2010-11-05 17:09:09 -04:00
@ast.columns << column
values << value
end
@ast.values = create_values values, @ast.columns
2010-08-13 21:28:38 -04:00
end
end
def create_values values, columns
Nodes::Values.new values, columns
end
end
end