aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sql_algebra/relations/join.rb
blob: 9a6196deacf511670d1ff9afc84862d837e04096 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Join
  attr_reader :relation1, :relation2, :predicates, :join_type
  
  def initialize(relation1, relation2, predicates, join_type)
    @relation1, @relation2, @predicates, @join_type = relation1, relation2, predicates, join_type
  end
  
  def to_sql(builder = JoinsBuilder.new)
    builder.call do
      send(join_type, relation2.table) do
        predicates.each { |p| p.to_sql(self) }
      end
    end
  end
end