diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sql_algebra/relations/order_relation.rb | 8 | ||||
-rw-r--r-- | lib/sql_algebra/relations/projection_relation.rb | 6 | ||||
-rw-r--r-- | lib/sql_algebra/relations/range_relation.rb | 7 |
3 files changed, 21 insertions, 0 deletions
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 |