From 0496a59e1fe0caf2d295defb588a00460cf15efb Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Mon, 31 Dec 2007 13:25:32 -0800 Subject: more to_sql --- lib/sql_algebra/relations/order_relation.rb | 8 ++++++++ lib/sql_algebra/relations/projection_relation.rb | 6 ++++++ lib/sql_algebra/relations/range_relation.rb | 7 +++++++ 3 files changed, 21 insertions(+) (limited to 'lib/sql_algebra') diff --git a/lib/sql_algebra/relations/order_relation.rb b/lib/sql_algebra/relations/order_relation.rb index 8d07c58d64..e3c29dcc27 100644 --- a/lib/sql_algebra/relations/order_relation.rb +++ b/lib/sql_algebra/relations/order_relation.rb @@ -8,4 +8,12 @@ class OrderRelation < Relation def ==(other) relation == other.relation and attributes.eql?(other.attributes) end + + def to_sql(builder = SelectBuilder.new) + relation.to_sql(builder).call do + attributes.each do |attribute| + order_by attribute.to_sql(self) + end + end + end end \ No newline at end of file diff --git a/lib/sql_algebra/relations/projection_relation.rb b/lib/sql_algebra/relations/projection_relation.rb index caebfc1b62..ca5f0bfca4 100644 --- a/lib/sql_algebra/relations/projection_relation.rb +++ b/lib/sql_algebra/relations/projection_relation.rb @@ -8,4 +8,10 @@ class ProjectionRelation < Relation def ==(other) relation == other.relation and attributes.eql?(other.attributes) end + + def to_sql(builder = SelectBuilder.new) + relation.to_sql(builder).call do + select attributes.collect { |a| a.to_sql(self) } + end + end end \ No newline at end of file diff --git a/lib/sql_algebra/relations/range_relation.rb b/lib/sql_algebra/relations/range_relation.rb index fd7e2898fa..9225d5615b 100644 --- a/lib/sql_algebra/relations/range_relation.rb +++ b/lib/sql_algebra/relations/range_relation.rb @@ -8,4 +8,11 @@ class RangeRelation < Relation def ==(other) relation == other.relation and range == other.range end + + def to_sql(builder = SelectBuilder.new) + relation.to_sql(builder).call do + limit range.last - range.first + 1 + offset range.first + end + end end \ No newline at end of file -- cgit v1.2.3