aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-04-21 15:28:21 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2011-04-21 15:28:21 -0500
commitcae83ce964b9919b890bb7fa6f920a536e6b5425 (patch)
treec0d11479ee90c9ead48cef7a3db1e297ee333489 /lib/arel
parent885a3acb1ce183189b8628f14fa834b3e1ba39ec (diff)
downloadrails-cae83ce964b9919b890bb7fa6f920a536e6b5425.tar.gz
rails-cae83ce964b9919b890bb7fa6f920a536e6b5425.tar.bz2
rails-cae83ce964b9919b890bb7fa6f920a536e6b5425.zip
adding a DISTINCT node
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/nodes/select_core.rb17
-rw-r--r--lib/arel/nodes/unary.rb6
-rw-r--r--lib/arel/visitors/to_sql.rb5
3 files changed, 21 insertions, 7 deletions
diff --git a/lib/arel/nodes/select_core.rb b/lib/arel/nodes/select_core.rb
index 7f577e0a05..bee0a5930c 100644
--- a/lib/arel/nodes/select_core.rb
+++ b/lib/arel/nodes/select_core.rb
@@ -2,15 +2,18 @@ module Arel
module Nodes
class SelectCore < Arel::Nodes::Node
attr_accessor :top, :projections, :wheres, :groups
- attr_accessor :having, :source
+ attr_accessor :having, :source, :set_quantifier
def initialize
- @source = JoinSource.new nil
- @top = nil
- @projections = []
- @wheres = []
- @groups = []
- @having = nil
+ @source = JoinSource.new nil
+ @top = nil
+
+ # http://savage.net.au/SQL/sql-92.bnf.html#set%20quantifier
+ @set_quantifier = nil
+ @projections = []
+ @wheres = []
+ @groups = []
+ @having = nil
end
def from
diff --git a/lib/arel/nodes/unary.rb b/lib/arel/nodes/unary.rb
index 1c834913fa..e6e40e6b13 100644
--- a/lib/arel/nodes/unary.rb
+++ b/lib/arel/nodes/unary.rb
@@ -23,5 +23,11 @@ module Arel
}.each do |name|
const_set(name, Class.new(Unary))
end
+
+ class Distinct < Unary
+ def initialize expr = nil
+ super
+ end
+ end
end
end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 061e46a436..6aba31d94d 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -125,6 +125,7 @@ key on UpdateManager using UpdateManager#key=
[
"SELECT",
(visit(o.top) if o.top),
+ (visit(o.set_quantifier) if o.set_quantifier),
"#{o.projections.map { |x| visit x }.join ', '}",
visit(o.source),
("WHERE #{o.wheres.map { |x| visit x }.join ' AND ' }" unless o.wheres.empty?),
@@ -137,6 +138,10 @@ key on UpdateManager using UpdateManager#key=
visit o.expr
end
+ def visit_Arel_Nodes_Distinct o
+ 'DISTINCT'
+ end
+
def visit_Arel_Nodes_With o
"WITH #{o.children.map { |x| visit x }.join(', ')}"
end