aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-08 16:20:48 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-08 16:20:48 -0700
commitc8140beae74bd63f2c1edd31d6e7ce9bcd31169d (patch)
treed1d5aed6ab16adada7807bd34964f31464c01931 /lib
parent4e2e1cc63a81bf549712c4cacfe1f3dc32e632a2 (diff)
parent55c0071ce3685a78b4f039be24b2ab40b8779467 (diff)
downloadrails-c8140beae74bd63f2c1edd31d6e7ce9bcd31169d.tar.gz
rails-c8140beae74bd63f2c1edd31d6e7ce9bcd31169d.tar.bz2
rails-c8140beae74bd63f2c1edd31d6e7ce9bcd31169d.zip
Merge branch 'master' into collector
* master: remove order_clauses since we do not use it fix whitespace and unsupported method args Add Regexp and NotRegexp nodes for PostgreSQL Revert "Merge pull request #253 from corrupt952/master" flatten object.children in visit_Arel_Node_And Added right and full outer joins Conflicts: lib/arel/visitors/to_sql.rb lib/arel/visitors/visitor.rb
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/nodes.rb2
-rw-r--r--lib/arel/nodes/binary.rb2
-rw-r--r--lib/arel/nodes/full_outer_join.rb6
-rw-r--r--lib/arel/nodes/right_outer_join.rb6
-rw-r--r--lib/arel/select_manager.rb7
-rw-r--r--lib/arel/visitors.rb1
-rw-r--r--lib/arel/visitors/bind_substitute.rb9
-rw-r--r--lib/arel/visitors/depth_first.rb4
-rw-r--r--lib/arel/visitors/dot.rb4
-rw-r--r--lib/arel/visitors/order_clauses.rb11
-rw-r--r--lib/arel/visitors/postgresql.rb8
-rw-r--r--lib/arel/visitors/to_sql.rb20
12 files changed, 58 insertions, 22 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index 6ce1ed7dba..a68e327983 100644
--- a/lib/arel/nodes.rb
+++ b/lib/arel/nodes.rb
@@ -45,8 +45,10 @@ require 'arel/nodes/named_function'
require 'arel/nodes/window'
# joins
+require 'arel/nodes/full_outer_join'
require 'arel/nodes/inner_join'
require 'arel/nodes/outer_join'
+require 'arel/nodes/right_outer_join'
require 'arel/nodes/string_join'
require 'arel/nodes/sql_literal'
diff --git a/lib/arel/nodes/binary.rb b/lib/arel/nodes/binary.rb
index 0e7e281b4b..939684957f 100644
--- a/lib/arel/nodes/binary.rb
+++ b/lib/arel/nodes/binary.rb
@@ -40,7 +40,9 @@ module Arel
Matches
NotEqual
NotIn
+ NotRegexp
Or
+ Regexp
Union
UnionAll
Intersect
diff --git a/lib/arel/nodes/full_outer_join.rb b/lib/arel/nodes/full_outer_join.rb
new file mode 100644
index 0000000000..708f161c9a
--- /dev/null
+++ b/lib/arel/nodes/full_outer_join.rb
@@ -0,0 +1,6 @@
+module Arel
+ module Nodes
+ class FullOuterJoin < Arel::Nodes::Join
+ end
+ end
+end
diff --git a/lib/arel/nodes/right_outer_join.rb b/lib/arel/nodes/right_outer_join.rb
new file mode 100644
index 0000000000..ea1ddb7d52
--- /dev/null
+++ b/lib/arel/nodes/right_outer_join.rb
@@ -0,0 +1,6 @@
+module Arel
+ module Nodes
+ class RightOuterJoin < Arel::Nodes::Join
+ end
+ end
+end
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 5ab2778778..f49f76d98f 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -220,13 +220,6 @@ module Arel
Nodes::SqlLiteral.new sql
end
- def order_clauses
- visitor = Visitors::OrderClauses.new(@engine.connection)
- visitor.accept(@ast).map { |x|
- Nodes::SqlLiteral.new x
- }
- end
-
def join_sources
@ctx.source.right
end
diff --git a/lib/arel/visitors.rb b/lib/arel/visitors.rb
index 8276eace2b..3986ad9ce5 100644
--- a/lib/arel/visitors.rb
+++ b/lib/arel/visitors.rb
@@ -8,7 +8,6 @@ require 'arel/visitors/mssql'
require 'arel/visitors/oracle'
require 'arel/visitors/join_sql'
require 'arel/visitors/where_sql'
-require 'arel/visitors/order_clauses'
require 'arel/visitors/dot'
require 'arel/visitors/ibm_db'
require 'arel/visitors/informix'
diff --git a/lib/arel/visitors/bind_substitute.rb b/lib/arel/visitors/bind_substitute.rb
new file mode 100644
index 0000000000..0503a9c986
--- /dev/null
+++ b/lib/arel/visitors/bind_substitute.rb
@@ -0,0 +1,9 @@
+module Arel
+ module Visitors
+ class BindSubstitute
+ def initialize delegte
+ @delegate = delegate
+ end
+ end
+ end
+end
diff --git a/lib/arel/visitors/depth_first.rb b/lib/arel/visitors/depth_first.rb
index 1770ab21d5..4d2ecfa5e1 100644
--- a/lib/arel/visitors/depth_first.rb
+++ b/lib/arel/visitors/depth_first.rb
@@ -67,6 +67,7 @@ module Arel
alias :visit_Arel_Nodes_DeleteStatement :binary
alias :visit_Arel_Nodes_DoesNotMatch :binary
alias :visit_Arel_Nodes_Equality :binary
+ alias :visit_Arel_Nodes_FullOuterJoin :binary
alias :visit_Arel_Nodes_GreaterThan :binary
alias :visit_Arel_Nodes_GreaterThanOrEqual :binary
alias :visit_Arel_Nodes_In :binary
@@ -78,8 +79,11 @@ module Arel
alias :visit_Arel_Nodes_Matches :binary
alias :visit_Arel_Nodes_NotEqual :binary
alias :visit_Arel_Nodes_NotIn :binary
+ alias :visit_Arel_Nodes_NotRegexp :binary
alias :visit_Arel_Nodes_Or :binary
alias :visit_Arel_Nodes_OuterJoin :binary
+ alias :visit_Arel_Nodes_Regexp :binary
+ alias :visit_Arel_Nodes_RightOuterJoin :binary
alias :visit_Arel_Nodes_TableAlias :binary
alias :visit_Arel_Nodes_Values :binary
diff --git a/lib/arel/visitors/dot.rb b/lib/arel/visitors/dot.rb
index b2fa6bfbd5..99f4c467d2 100644
--- a/lib/arel/visitors/dot.rb
+++ b/lib/arel/visitors/dot.rb
@@ -54,7 +54,9 @@ module Arel
visit_edge o, "left"
visit_edge o, "right"
end
- alias :visit_Arel_Nodes_OuterJoin :visit_Arel_Nodes_InnerJoin
+ alias :visit_Arel_Nodes_FullOuterJoin :visit_Arel_Nodes_InnerJoin
+ alias :visit_Arel_Nodes_OuterJoin :visit_Arel_Nodes_InnerJoin
+ alias :visit_Arel_Nodes_RightOuterJoin :visit_Arel_Nodes_InnerJoin
def visit_Arel_Nodes_DeleteStatement o
visit_edge o, "relation"
diff --git a/lib/arel/visitors/order_clauses.rb b/lib/arel/visitors/order_clauses.rb
deleted file mode 100644
index 11dbfdad2a..0000000000
--- a/lib/arel/visitors/order_clauses.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module Arel
- module Visitors
- class OrderClauses < Arel::Visitors::ToSql
- private
-
- def visit_Arel_Nodes_SelectStatement o
- o.orders.map { |x| visit x }
- end
- end
- end
-end
diff --git a/lib/arel/visitors/postgresql.rb b/lib/arel/visitors/postgresql.rb
index 812710181c..49f7482e7d 100644
--- a/lib/arel/visitors/postgresql.rb
+++ b/lib/arel/visitors/postgresql.rb
@@ -11,6 +11,14 @@ module Arel
"#{visit o.left} NOT ILIKE #{visit o.right}"
end
+ def visit_Arel_Nodes_Regexp o
+ "#{visit o.left} ~ #{visit o.right}"
+ end
+
+ def visit_Arel_Nodes_NotRegexp o
+ "#{visit o.left} !~ #{visit o.right}"
+ end
+
def visit_Arel_Nodes_DistinctOn o
"DISTINCT ON ( #{visit o.expr} )"
end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 545f95df2a..d8883073d0 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -470,19 +470,35 @@ module Arel
collector << " "
end
if o.right.any?
- o.right.map { |j| visit j }.join(' ')
+ collector = inject_join o.right, collector, ' '
end
collector
end
+ def visit_Arel_Nodes_Regexp o, collector
+ raise NotImplementedError, '~ not implemented for this db'
+ end
+
+ def visit_Arel_Nodes_NotRegexp o, collector
+ raise NotImplementedError, '!~ not implemented for this db'
+ end
+
def visit_Arel_Nodes_StringJoin o
visit o.left
end
+ def visit_Arel_Nodes_FullOuterJoin o
+ "FULL OUTER JOIN #{visit o.left} #{visit o.right}"
+ end
+
def visit_Arel_Nodes_OuterJoin o
"LEFT OUTER JOIN #{visit o.left} #{visit o.right}"
end
+ def visit_Arel_Nodes_RightOuterJoin o
+ "RIGHT OUTER JOIN #{visit o.left} #{visit o.right}"
+ end
+
def visit_Arel_Nodes_InnerJoin o
s = "INNER JOIN #{visit o.left}"
if o.right
@@ -612,7 +628,7 @@ module Arel
quote(o, column_for(a))
end
- def unsupported o, a
+ def unsupported o
raise "unsupported: #{o.class.name}"
end