aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sql_algebra/relations/projection_relation.rb
blob: 0b5d645d79a8a09364de12cab17cd45327f06194 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class ProjectionRelation < Relation
  attr_reader :relation, :attributes
  
  def initialize(relation, *attributes)
    @relation, @attributes = relation, attributes
  end
  
  def ==(other)
    relation == other.relation and attributes.eql?(other.attributes)
  end
  
  def to_sql(builder = SelectBuilder.new)
    relation.to_sql(builder).call do
      select do
        attributes.collect { |a| a.to_sql(self) }
      end
    end
  end
end