aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/TODO4
-rw-r--r--lib/arel/algebra/relations/row.rb5
-rw-r--r--lib/arel/engines/memory/relations/array.rb4
-rw-r--r--lib/arel/engines/memory/relations/compound.rb2
-rw-r--r--lib/arel/engines/memory/relations/operations.rb4
-rw-r--r--lib/arel/engines/sql/engine.rb4
-rw-r--r--lib/arel/engines/sql/primitives.rb4
-rw-r--r--lib/arel/engines/sql/relations/table.rb4
-rw-r--r--spec/arel/engines/memory/integration/joins/cross_engine_spec.rb31
9 files changed, 54 insertions, 8 deletions
diff --git a/doc/TODO b/doc/TODO
index 5e3a7ee3ab..901d6ab13f 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -1,8 +1,7 @@
todo:
-- insertions for in memory
- cross-engine joins
- blocks for joins
-- test sql insertions
+- fix sql insertions
- implement mnesia adapter
- rename externalize to derived.
@@ -94,6 +93,7 @@ done:
- implement joins in memory
- result sets should be array relations
- fix AR
+- insertions for in memory
icebox:
- #bind in Attribute and Expression should be doing a descend?
diff --git a/lib/arel/algebra/relations/row.rb b/lib/arel/algebra/relations/row.rb
index 3731dd9696..e8484944bd 100644
--- a/lib/arel/algebra/relations/row.rb
+++ b/lib/arel/algebra/relations/row.rb
@@ -4,12 +4,13 @@ module Arel
deriving :==, :initialize
def [](attribute)
- tuple[relation.position_of(attribute)]
+ attribute.type_cast(tuple[relation.position_of(attribute)])
end
def slice(*attributes)
Row.new(relation, attributes.inject([]) do |cheese, attribute|
- cheese << self[attribute]
+ # FIXME TESTME method chaining
+ cheese << tuple[relation.relation.position_of(attribute)]
cheese
end)
end
diff --git a/lib/arel/engines/memory/relations/array.rb b/lib/arel/engines/memory/relations/array.rb
index 15a3e95e1b..6e2dc29252 100644
--- a/lib/arel/engines/memory/relations/array.rb
+++ b/lib/arel/engines/memory/relations/array.rb
@@ -14,6 +14,10 @@ module Arel
end
end
+ def format(attribute, value)
+ value
+ end
+
def eval
@array.collect { |r| Row.new(self, r) }
end
diff --git a/lib/arel/engines/memory/relations/compound.rb b/lib/arel/engines/memory/relations/compound.rb
index 3791fa4622..9e7827dfb3 100644
--- a/lib/arel/engines/memory/relations/compound.rb
+++ b/lib/arel/engines/memory/relations/compound.rb
@@ -3,7 +3,7 @@ module Arel
delegate :array, :to => :relation
def unoperated_rows
- relation.eval.collect { |row| row.bind(self) }
+ relation.call.collect { |row| row.bind(self) }
end
end
end
diff --git a/lib/arel/engines/memory/relations/operations.rb b/lib/arel/engines/memory/relations/operations.rb
index e35fbe3234..e0fd2824b3 100644
--- a/lib/arel/engines/memory/relations/operations.rb
+++ b/lib/arel/engines/memory/relations/operations.rb
@@ -47,8 +47,8 @@ module Arel
class Join < Relation
def eval
result = []
- relation1.eval.each do |row1|
- relation2.eval.each do |row2|
+ relation1.call.each do |row1|
+ relation2.call.each do |row2|
combined_row = row1.combine(row2, self)
if predicates.all? { |p| p.eval(combined_row) }
result << combined_row
diff --git a/lib/arel/engines/sql/engine.rb b/lib/arel/engines/sql/engine.rb
index 0700ae9733..d27d93a5dc 100644
--- a/lib/arel/engines/sql/engine.rb
+++ b/lib/arel/engines/sql/engine.rb
@@ -20,7 +20,9 @@ module Arel
def read(relation)
# FIXME
- class << rows = connection.execute(relation.to_sql)
+ rows = connection.select_rows(relation.to_sql)
+
+ class << rows
include Enumerable
end
diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb
index 9e9143ac0f..22ee19dcf0 100644
--- a/lib/arel/engines/sql/primitives.rb
+++ b/lib/arel/engines/sql/primitives.rb
@@ -4,6 +4,10 @@ module Arel
original_relation.column_for(self)
end
+ def type_cast(value)
+ root.relation.format(self, value)
+ end
+
def format(object)
object.to_sql(Sql::Attribute.new(self))
end
diff --git a/lib/arel/engines/sql/relations/table.rb b/lib/arel/engines/sql/relations/table.rb
index 2653744149..e842f85ed1 100644
--- a/lib/arel/engines/sql/relations/table.rb
+++ b/lib/arel/engines/sql/relations/table.rb
@@ -16,6 +16,10 @@ module Arel
end
end
+ def format(attribute, value)
+ attribute.column.type_cast(value)
+ end
+
def column_for(attribute)
has_attribute?(attribute) and columns.detect { |c| c.name == attribute.name.to_s }
end
diff --git a/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb b/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb
new file mode 100644
index 0000000000..dd923ee6eb
--- /dev/null
+++ b/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb
@@ -0,0 +1,31 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')
+
+module Arel
+ describe Join do
+ before do
+ @users = Array.new([
+ [1, 'bryan' ],
+ [2, 'emilio' ],
+ [3, 'nick']
+ ], [:id, :name])
+ @photos = Table.new(:photos)
+ @photos.delete
+ @photos \
+ .insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6) \
+ .insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42)
+ end
+
+ it 'joins across engines' do
+ @users \
+ .join(@photos) \
+ .on(@users[:id].eq(@photos[:user_id])) \
+ .project(@users[:name], @photos[:camera_id]) \
+ .let do |relation|
+ relation.call.should == [
+ Row.new(relation, ['bryan', '6']),
+ Row.new(relation, ['emilio', '42'])
+ ]
+ end
+ end
+ end
+end \ No newline at end of file