diff options
Diffstat (limited to 'lib/arel/relations')
-rw-r--r-- | lib/arel/relations/array.rb | 19 | ||||
-rw-r--r-- | lib/arel/relations/relation.rb | 9 | ||||
-rw-r--r-- | lib/arel/relations/writes/delete.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/writes/insert.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/writes/update.rb | 4 |
5 files changed, 27 insertions, 13 deletions
diff --git a/lib/arel/relations/array.rb b/lib/arel/relations/array.rb new file mode 100644 index 0000000000..dac65abbc2 --- /dev/null +++ b/lib/arel/relations/array.rb @@ -0,0 +1,19 @@ +module Arel + class Array < Relation + include Recursion::BaseCase + + def initialize(array, attribute_names) + @array, @attribute_names = array, attribute_names + end + + def attributes + @attributes ||= @attribute_names.collect do |name| + Attribute.new(self, name.to_sym) + end + end + + def call(connection = nil) + @array.collect { |row| attributes.zip(row).to_hash } + end + end +end
\ No newline at end of file diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb index 5d2c336a15..ef295dfdd7 100644 --- a/lib/arel/relations/relation.rb +++ b/lib/arel/relations/relation.rb @@ -32,13 +32,8 @@ module Arel "IN" end - def call(connection = engine) - results = connection.execute(to_sql) - rows = [] - results.each do |row| - rows << attributes.zip(row).to_hash - end - rows + def call + engine.read(self) end def bind(relation) diff --git a/lib/arel/relations/writes/delete.rb b/lib/arel/relations/writes/delete.rb index b1ff3bef27..0a04454e7f 100644 --- a/lib/arel/relations/writes/delete.rb +++ b/lib/arel/relations/writes/delete.rb @@ -12,8 +12,8 @@ module Arel ].compact.join("\n") end - def call(connection = engine) - connection.delete(to_sql) + def call + engine.delete(self) end end end diff --git a/lib/arel/relations/writes/insert.rb b/lib/arel/relations/writes/insert.rb index d579ad06d0..d05bd9cdc8 100644 --- a/lib/arel/relations/writes/insert.rb +++ b/lib/arel/relations/writes/insert.rb @@ -16,8 +16,8 @@ module Arel ].join("\n") end - def call(connection = engine) - connection.insert(to_sql) + def call + engine.create(self) end end end diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/relations/writes/update.rb index 2e90de3a52..fd0aadb479 100644 --- a/lib/arel/relations/writes/update.rb +++ b/lib/arel/relations/writes/update.rb @@ -18,8 +18,8 @@ module Arel ].join("\n") end - def call(connection = engine) - connection.update(to_sql) + def call + engine.update(self) end end end |