aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/sql_algebra/relations/compound_relation.rb3
-rw-r--r--lib/sql_algebra/relations/join.rb15
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/sql_algebra/relations/compound_relation.rb b/lib/sql_algebra/relations/compound_relation.rb
new file mode 100644
index 0000000000..a8e9a41b5e
--- /dev/null
+++ b/lib/sql_algebra/relations/compound_relation.rb
@@ -0,0 +1,3 @@
+class CompoundRelation < Relation
+ delegate :attributes, :attribute, :joins, :select, :orders, :table, :to => :relation
+end \ No newline at end of file
diff --git a/lib/sql_algebra/relations/join.rb b/lib/sql_algebra/relations/join.rb
new file mode 100644
index 0000000000..9a6196deac
--- /dev/null
+++ b/lib/sql_algebra/relations/join.rb
@@ -0,0 +1,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 \ No newline at end of file