aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2007-12-30 13:48:13 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2007-12-30 13:48:13 -0800
commit63b9c6a41f7ab92a16362a50b60bcea7e20cb427 (patch)
treeca3d84fe2b26d906035fb796e811b364a4cb5c0d /lib
parentf9cc8bba39b1deb6b3f70cecb96beaf988054915 (diff)
downloadrails-63b9c6a41f7ab92a16362a50b60bcea7e20cb427.tar.gz
rails-63b9c6a41f7ab92a16362a50b60bcea7e20cb427.tar.bz2
rails-63b9c6a41f7ab92a16362a50b60bcea7e20cb427.zip
joins
Diffstat (limited to 'lib')
-rw-r--r--lib/sql_algebra.rb4
-rw-r--r--lib/sql_algebra/relations/join_operation.rb2
-rw-r--r--lib/sql_algebra/relations/relation.rb29
3 files changed, 30 insertions, 5 deletions
diff --git a/lib/sql_algebra.rb b/lib/sql_algebra.rb
index 7407dc264b..8adbed150d 100644
--- a/lib/sql_algebra.rb
+++ b/lib/sql_algebra.rb
@@ -5,7 +5,11 @@ require 'active_support'
require 'sql_algebra/relations/relation'
require 'sql_algebra/relations/table_relation'
require 'sql_algebra/relations/join_operation'
+require 'sql_algebra/relations/inner_join_operation'
+require 'sql_algebra/relations/left_outer_join_operation'
require 'sql_algebra/relations/join_relation'
+require 'sql_algebra/relations/inner_join_relation'
+require 'sql_algebra/relations/left_outer_join_relation'
require 'sql_algebra/relations/attribute'
require 'sql_algebra/relations/projection_relation'
require 'sql_algebra/relations/selection_relation'
diff --git a/lib/sql_algebra/relations/join_operation.rb b/lib/sql_algebra/relations/join_operation.rb
index dab8e9e6bd..2b4548a041 100644
--- a/lib/sql_algebra/relations/join_operation.rb
+++ b/lib/sql_algebra/relations/join_operation.rb
@@ -6,7 +6,7 @@ class JoinOperation
end
def on(*predicates)
- JoinRelation.new(relation1, relation2, *predicates)
+ relation_class.new(relation1, relation2, *predicates)
end
def ==(other)
diff --git a/lib/sql_algebra/relations/relation.rb b/lib/sql_algebra/relations/relation.rb
index f1f8fc5884..bd812b368d 100644
--- a/lib/sql_algebra/relations/relation.rb
+++ b/lib/sql_algebra/relations/relation.rb
@@ -1,13 +1,34 @@
class Relation
- def *(other)
- JoinOperation.new(self, other)
+ def <=>(other)
+ InnerJoinOperation.new(self, other)
end
- def [](attribute_name)
- Attribute.new(self, attribute_name)
+ def <<(other)
+ LeftOuterJoinOperation.new(self, other)
+ end
+
+ def [](index)
+ case index
+ when Symbol
+ Attribute.new(self, index)
+ when Range
+ RangeRelation.new(self, index)
+ end
end
def include?(attribute)
RelationInclusionPredicate.new(attribute, self)
end
+
+ def select(*predicates)
+ SelectionRelation.new(self, *predicates)
+ end
+
+ def project(*attributes)
+ ProjectionRelation.new(self, *attributes)
+ end
+
+ def order(*attributes)
+ OrderRelation.new(self, *attributes)
+ end
end \ No newline at end of file