aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/nodes
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/nodes')
-rw-r--r--lib/arel/nodes/and.rb19
-rw-r--r--lib/arel/nodes/as.rb6
-rw-r--r--lib/arel/nodes/assignment.rb6
-rw-r--r--lib/arel/nodes/avg.rb6
-rw-r--r--lib/arel/nodes/between.rb6
-rw-r--r--lib/arel/nodes/binary.rb24
-rw-r--r--lib/arel/nodes/does_not_match.rb6
-rw-r--r--lib/arel/nodes/exists.rb7
-rw-r--r--lib/arel/nodes/function.rb10
-rw-r--r--lib/arel/nodes/greater_than.rb6
-rw-r--r--lib/arel/nodes/greater_than_or_equal.rb6
-rw-r--r--lib/arel/nodes/group.rb6
-rw-r--r--lib/arel/nodes/grouping.rb6
-rw-r--r--lib/arel/nodes/having.rb6
-rw-r--r--lib/arel/nodes/join.rb13
-rw-r--r--lib/arel/nodes/join_source.rb14
-rw-r--r--lib/arel/nodes/less_than.rb6
-rw-r--r--lib/arel/nodes/less_than_or_equal.rb6
-rw-r--r--lib/arel/nodes/limit.rb7
-rw-r--r--lib/arel/nodes/matches.rb6
-rw-r--r--lib/arel/nodes/max.rb6
-rw-r--r--lib/arel/nodes/min.rb6
-rw-r--r--lib/arel/nodes/node.rb5
-rw-r--r--lib/arel/nodes/not.rb6
-rw-r--r--lib/arel/nodes/not_equal.rb6
-rw-r--r--lib/arel/nodes/not_in.rb6
-rw-r--r--lib/arel/nodes/offset.rb7
-rw-r--r--lib/arel/nodes/on.rb6
-rw-r--r--lib/arel/nodes/or.rb6
-rw-r--r--lib/arel/nodes/select_core.rb21
-rw-r--r--lib/arel/nodes/select_statement.rb1
-rw-r--r--lib/arel/nodes/string_join.rb6
-rw-r--r--lib/arel/nodes/sum.rb6
-rw-r--r--lib/arel/nodes/table_alias.rb2
-rw-r--r--lib/arel/nodes/top.rb6
-rw-r--r--lib/arel/nodes/unary.rb14
-rw-r--r--lib/arel/nodes/unqualified_column.rb4
-rw-r--r--lib/arel/nodes/update_statement.rb6
38 files changed, 112 insertions, 180 deletions
diff --git a/lib/arel/nodes/and.rb b/lib/arel/nodes/and.rb
index 80f420b4f1..b4443c3d27 100644
--- a/lib/arel/nodes/and.rb
+++ b/lib/arel/nodes/and.rb
@@ -1,6 +1,23 @@
module Arel
module Nodes
- class And < Arel::Nodes::Binary
+ class And < Arel::Nodes::Node
+ attr_reader :children
+
+ def initialize children, right = nil
+ unless Array === children
+ warn "(#{caller.first}) AND nodes should be created with a list"
+ children = [children, right]
+ end
+ @children = children
+ end
+
+ def left
+ children.first
+ end
+
+ def right
+ children[1]
+ end
end
end
end
diff --git a/lib/arel/nodes/as.rb b/lib/arel/nodes/as.rb
deleted file mode 100644
index 9009fe12f4..0000000000
--- a/lib/arel/nodes/as.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class As < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/assignment.rb b/lib/arel/nodes/assignment.rb
deleted file mode 100644
index 693bd5afe6..0000000000
--- a/lib/arel/nodes/assignment.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Assignment < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/avg.rb b/lib/arel/nodes/avg.rb
deleted file mode 100644
index 8fc86fc21e..0000000000
--- a/lib/arel/nodes/avg.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Avg < Arel::Nodes::Function
- end
- end
-end
diff --git a/lib/arel/nodes/between.rb b/lib/arel/nodes/between.rb
deleted file mode 100644
index 2e7596cdae..0000000000
--- a/lib/arel/nodes/between.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Between < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/binary.rb b/lib/arel/nodes/binary.rb
index cfa75909c5..0d02554199 100644
--- a/lib/arel/nodes/binary.rb
+++ b/lib/arel/nodes/binary.rb
@@ -7,6 +7,30 @@ module Arel
@left = left
@right = right
end
+
+ def initialize_copy other
+ super
+ @left = @left.clone if @left
+ @right = @right.clone if @right
+ end
+ end
+
+ %w{
+ As
+ Assignment
+ Between
+ DoesNotMatch
+ GreaterThan
+ GreaterThanOrEqual
+ Join
+ LessThan
+ LessThanOrEqual
+ Matches
+ NotEqual
+ NotIn
+ Or
+ }.each do |name|
+ const_set name, Class.new(Binary)
end
end
end
diff --git a/lib/arel/nodes/does_not_match.rb b/lib/arel/nodes/does_not_match.rb
deleted file mode 100644
index 33bdeab005..0000000000
--- a/lib/arel/nodes/does_not_match.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class DoesNotMatch < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/exists.rb b/lib/arel/nodes/exists.rb
deleted file mode 100644
index 18ba8403b4..0000000000
--- a/lib/arel/nodes/exists.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Arel
- module Nodes
- class Exists < Arel::Nodes::Function
- alias :select_stmt :expressions
- end
- end
-end
diff --git a/lib/arel/nodes/function.rb b/lib/arel/nodes/function.rb
index 133dd66019..e4e45bff31 100644
--- a/lib/arel/nodes/function.rb
+++ b/lib/arel/nodes/function.rb
@@ -14,5 +14,15 @@ module Arel
self
end
end
+
+ %w{
+ Sum
+ Exists
+ Max
+ Min
+ Avg
+ }.each do |name|
+ const_set(name, Class.new(Function))
+ end
end
end
diff --git a/lib/arel/nodes/greater_than.rb b/lib/arel/nodes/greater_than.rb
deleted file mode 100644
index 2e03cc2e18..0000000000
--- a/lib/arel/nodes/greater_than.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class GreaterThan < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/greater_than_or_equal.rb b/lib/arel/nodes/greater_than_or_equal.rb
deleted file mode 100644
index a8cfaab04e..0000000000
--- a/lib/arel/nodes/greater_than_or_equal.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class GreaterThanOrEqual < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/group.rb b/lib/arel/nodes/group.rb
deleted file mode 100644
index a7fa6f170d..0000000000
--- a/lib/arel/nodes/group.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Group < Arel::Nodes::Unary
- end
- end
-end
diff --git a/lib/arel/nodes/grouping.rb b/lib/arel/nodes/grouping.rb
deleted file mode 100644
index 18adeae97f..0000000000
--- a/lib/arel/nodes/grouping.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Grouping < Arel::Nodes::Unary
- end
- end
-end
diff --git a/lib/arel/nodes/having.rb b/lib/arel/nodes/having.rb
deleted file mode 100644
index 6972c58dda..0000000000
--- a/lib/arel/nodes/having.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Having < Arel::Nodes::Unary
- end
- end
-end
diff --git a/lib/arel/nodes/join.rb b/lib/arel/nodes/join.rb
deleted file mode 100644
index 07f8c98e85..0000000000
--- a/lib/arel/nodes/join.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module Arel
- module Nodes
- class Join < Arel::Nodes::Node
- attr_accessor :left, :right, :constraint
-
- def initialize left, right, constraint
- @left = left
- @right = right
- @constraint = constraint
- end
- end
- end
-end
diff --git a/lib/arel/nodes/join_source.rb b/lib/arel/nodes/join_source.rb
new file mode 100644
index 0000000000..c57ad0e930
--- /dev/null
+++ b/lib/arel/nodes/join_source.rb
@@ -0,0 +1,14 @@
+module Arel
+ module Nodes
+ ###
+ # Class that represents a join source
+ #
+ # http://www.sqlite.org/syntaxdiagrams.html#join-source
+
+ class JoinSource < Arel::Nodes::Binary
+ def initialize single_source, joinop = []
+ super
+ end
+ end
+ end
+end
diff --git a/lib/arel/nodes/less_than.rb b/lib/arel/nodes/less_than.rb
deleted file mode 100644
index cfaf716c42..0000000000
--- a/lib/arel/nodes/less_than.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class LessThan < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/less_than_or_equal.rb b/lib/arel/nodes/less_than_or_equal.rb
deleted file mode 100644
index 55449d12f1..0000000000
--- a/lib/arel/nodes/less_than_or_equal.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class LessThanOrEqual < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/limit.rb b/lib/arel/nodes/limit.rb
deleted file mode 100644
index 68ea95daf5..0000000000
--- a/lib/arel/nodes/limit.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Arel
- module Nodes
- class Limit < Arel::Nodes::Unary
- end
- end
-end
-
diff --git a/lib/arel/nodes/matches.rb b/lib/arel/nodes/matches.rb
deleted file mode 100644
index 5ef8ac8302..0000000000
--- a/lib/arel/nodes/matches.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Matches < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/max.rb b/lib/arel/nodes/max.rb
deleted file mode 100644
index 5af611b0d6..0000000000
--- a/lib/arel/nodes/max.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Max < Arel::Nodes::Function
- end
- end
-end
diff --git a/lib/arel/nodes/min.rb b/lib/arel/nodes/min.rb
deleted file mode 100644
index bdc1371858..0000000000
--- a/lib/arel/nodes/min.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Min < Arel::Nodes::Function
- end
- end
-end
diff --git a/lib/arel/nodes/node.rb b/lib/arel/nodes/node.rb
index 404ad22ece..711fa34b6d 100644
--- a/lib/arel/nodes/node.rb
+++ b/lib/arel/nodes/node.rb
@@ -3,6 +3,9 @@ module Arel
###
# Abstract base class for all AST nodes
class Node
+ include Arel::FactoryMethods
+ include Enumerable
+
###
# Factory method to create a Nodes::Not node that has the recipient of
# the caller as a child.
@@ -20,7 +23,7 @@ module Arel
###
# Factory method to create an Nodes::And node.
def and right
- Nodes::And.new self, right
+ Nodes::And.new [self, right]
end
# FIXME: this method should go away. I don't like people calling
diff --git a/lib/arel/nodes/not.rb b/lib/arel/nodes/not.rb
deleted file mode 100644
index de138435bb..0000000000
--- a/lib/arel/nodes/not.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Not < Arel::Nodes::Unary
- end
- end
-end
diff --git a/lib/arel/nodes/not_equal.rb b/lib/arel/nodes/not_equal.rb
deleted file mode 100644
index 7f892940cb..0000000000
--- a/lib/arel/nodes/not_equal.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class NotEqual < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/not_in.rb b/lib/arel/nodes/not_in.rb
deleted file mode 100644
index 6c01921a46..0000000000
--- a/lib/arel/nodes/not_in.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class NotIn < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/offset.rb b/lib/arel/nodes/offset.rb
deleted file mode 100644
index d93e46aa1f..0000000000
--- a/lib/arel/nodes/offset.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Arel
- module Nodes
- class Offset < Arel::Nodes::Unary
- alias :value :expr
- end
- end
-end
diff --git a/lib/arel/nodes/on.rb b/lib/arel/nodes/on.rb
deleted file mode 100644
index 953d64f9f1..0000000000
--- a/lib/arel/nodes/on.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class On < Arel::Nodes::Unary
- end
- end
-end
diff --git a/lib/arel/nodes/or.rb b/lib/arel/nodes/or.rb
deleted file mode 100644
index bdf7f6d9b3..0000000000
--- a/lib/arel/nodes/or.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Or < Arel::Nodes::Binary
- end
- end
-end
diff --git a/lib/arel/nodes/select_core.rb b/lib/arel/nodes/select_core.rb
index 501a2aaf7c..7f577e0a05 100644
--- a/lib/arel/nodes/select_core.rb
+++ b/lib/arel/nodes/select_core.rb
@@ -1,24 +1,35 @@
module Arel
module Nodes
class SelectCore < Arel::Nodes::Node
- attr_accessor :top, :froms, :projections, :wheres, :groups
- attr_accessor :having
+ attr_accessor :top, :projections, :wheres, :groups
+ attr_accessor :having, :source
def initialize
+ @source = JoinSource.new nil
@top = nil
- @froms = nil
@projections = []
@wheres = []
@groups = []
@having = nil
end
+ def from
+ @source.left
+ end
+
+ def from= value
+ @source.left = value
+ end
+
+ alias :froms= :from=
+ alias :froms :from
+
def initialize_copy other
super
- @froms = @froms.clone if @froms
+ @source = @source.clone if @source
@projections = @projections.clone
@wheres = @wheres.clone
- @group = @groups.clone
+ @groups = @groups.clone
@having = @having.clone if @having
end
end
diff --git a/lib/arel/nodes/select_statement.rb b/lib/arel/nodes/select_statement.rb
index 6881a66747..c9a0cde4e0 100644
--- a/lib/arel/nodes/select_statement.rb
+++ b/lib/arel/nodes/select_statement.rb
@@ -5,6 +5,7 @@ module Arel
attr_accessor :limit, :orders, :lock, :offset
def initialize cores = [SelectCore.new]
+ #puts caller
@cores = cores
@orders = []
@limit = nil
diff --git a/lib/arel/nodes/string_join.rb b/lib/arel/nodes/string_join.rb
index ea7912f92b..7fb0033c0f 100644
--- a/lib/arel/nodes/string_join.rb
+++ b/lib/arel/nodes/string_join.rb
@@ -1,10 +1,8 @@
module Arel
module Nodes
class StringJoin < Arel::Nodes::Join
- undef :constraint
-
- def initialize left, right
- super(left, right, nil)
+ def initialize left, right = nil
+ super
end
end
end
diff --git a/lib/arel/nodes/sum.rb b/lib/arel/nodes/sum.rb
deleted file mode 100644
index 3e043b7330..0000000000
--- a/lib/arel/nodes/sum.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Sum < Arel::Nodes::Function
- end
- end
-end
diff --git a/lib/arel/nodes/table_alias.rb b/lib/arel/nodes/table_alias.rb
index 723b025883..4f4d5e29e9 100644
--- a/lib/arel/nodes/table_alias.rb
+++ b/lib/arel/nodes/table_alias.rb
@@ -6,7 +6,7 @@ module Arel
alias :table_alias :name
def [] name
- Attribute.new self, name
+ Attribute.new(self, name)
end
end
end
diff --git a/lib/arel/nodes/top.rb b/lib/arel/nodes/top.rb
deleted file mode 100644
index 56e2e97e8d..0000000000
--- a/lib/arel/nodes/top.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Arel
- module Nodes
- class Top < Arel::Nodes::Unary
- end
- end
-end
diff --git a/lib/arel/nodes/unary.rb b/lib/arel/nodes/unary.rb
index edda89e1f0..e1576b9c99 100644
--- a/lib/arel/nodes/unary.rb
+++ b/lib/arel/nodes/unary.rb
@@ -2,10 +2,24 @@ module Arel
module Nodes
class Unary < Arel::Nodes::Node
attr_accessor :expr
+ alias :value :expr
def initialize expr
@expr = expr
end
end
+
+ %w{
+ Group
+ Grouping
+ Having
+ Limit
+ Not
+ Offset
+ On
+ Top
+ }.each do |name|
+ const_set(name, Class.new(Unary))
+ end
end
end
diff --git a/lib/arel/nodes/unqualified_column.rb b/lib/arel/nodes/unqualified_column.rb
index f7ba653c11..2820dba9d2 100644
--- a/lib/arel/nodes/unqualified_column.rb
+++ b/lib/arel/nodes/unqualified_column.rb
@@ -4,6 +4,10 @@ module Arel
alias :attribute :expr
alias :attribute= :expr=
+ def relation
+ @expr.relation
+ end
+
def column
@expr.column
end
diff --git a/lib/arel/nodes/update_statement.rb b/lib/arel/nodes/update_statement.rb
index 288e9f4676..c08f1b2c5e 100644
--- a/lib/arel/nodes/update_statement.rb
+++ b/lib/arel/nodes/update_statement.rb
@@ -2,13 +2,15 @@ module Arel
module Nodes
class UpdateStatement < Arel::Nodes::Node
attr_accessor :relation, :wheres, :values, :orders, :limit
+ attr_accessor :key
def initialize
@relation = nil
@wheres = []
@values = []
- @orders = []
- @limit = nil
+ @orders = []
+ @limit = nil
+ @key = nil
end
def initialize_copy other