From 63b9c6a41f7ab92a16362a50b60bcea7e20cb427 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sun, 30 Dec 2007 13:48:13 -0800 Subject: joins --- lib/sql_algebra/relations/join_operation.rb | 2 +- lib/sql_algebra/relations/relation.rb | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'lib/sql_algebra') 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 -- cgit v1.2.3