2010-08-13 18:30:22 -04:00
|
|
|
module Arel
|
|
|
|
class InsertManager < Arel::TreeManager
|
|
|
|
def initialize engine
|
|
|
|
super
|
|
|
|
@head = Nodes::InsertStatement.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def into table
|
|
|
|
@head.relation = table
|
|
|
|
self
|
|
|
|
end
|
2010-08-13 18:43:32 -04:00
|
|
|
|
|
|
|
def columns; @head.columns end
|
2010-09-09 18:20:25 -04:00
|
|
|
def values= val; @head.values = val; end
|
2010-08-13 21:28:38 -04:00
|
|
|
|
|
|
|
def insert fields
|
|
|
|
return if fields.empty?
|
|
|
|
|
2010-09-09 18:20:25 -04:00
|
|
|
if String === fields
|
|
|
|
@head.values = SqlLiteral.new(fields)
|
|
|
|
else
|
|
|
|
@head.relation ||= fields.first.first.relation
|
2010-08-13 21:28:38 -04:00
|
|
|
|
2010-09-09 18:20:25 -04:00
|
|
|
values = []
|
|
|
|
|
|
|
|
fields.each do |column, value|
|
|
|
|
@head.columns << column
|
|
|
|
values << value
|
|
|
|
end
|
2010-09-14 17:58:34 -04:00
|
|
|
@head.values = Nodes::Values.new values, @head.columns
|
2010-08-13 21:28:38 -04:00
|
|
|
end
|
|
|
|
end
|
2010-08-13 18:30:22 -04:00
|
|
|
end
|
|
|
|
end
|