diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-01-06 00:32:10 -0200 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-01-06 00:32:10 -0200 |
commit | ffc4b8e93af4356110c7a2573cc3340145baa02b (patch) | |
tree | e19640d2eabfeabad80c61a95a589a8b42d56703 /lib/arel | |
parent | dfd22638c2773d843ea1d2e56992a6ac355b3ecb (diff) | |
parent | 83c47c1962827698eb0ed58d191f121cedf89385 (diff) | |
download | rails-ffc4b8e93af4356110c7a2573cc3340145baa02b.tar.gz rails-ffc4b8e93af4356110c7a2573cc3340145baa02b.tar.bz2 rails-ffc4b8e93af4356110c7a2573cc3340145baa02b.zip |
Merge pull request #410 from kbrock/concat
Add database specific string concatenation
Diffstat (limited to 'lib/arel')
-rw-r--r-- | lib/arel/nodes/infix_operation.rb | 7 | ||||
-rw-r--r-- | lib/arel/predications.rb | 4 | ||||
-rw-r--r-- | lib/arel/visitors/depth_first.rb | 1 | ||||
-rw-r--r-- | lib/arel/visitors/dot.rb | 1 | ||||
-rw-r--r-- | lib/arel/visitors/mysql.rb | 8 |
5 files changed, 20 insertions, 1 deletions
diff --git a/lib/arel/nodes/infix_operation.rb b/lib/arel/nodes/infix_operation.rb index 3911a1e05e..a3f04da6fa 100644 --- a/lib/arel/nodes/infix_operation.rb +++ b/lib/arel/nodes/infix_operation.rb @@ -40,5 +40,10 @@ module Arel end end + class Concat < InfixOperation + def initialize left, right + super('||', left, right) + end + end end -end
\ No newline at end of file +end diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb index e9078e9c4b..81bf3b4d95 100644 --- a/lib/arel/predications.rb +++ b/lib/arel/predications.rb @@ -202,6 +202,10 @@ Passing a range to `#not_in` is deprecated. Call `#not_between`, instead. Nodes::Case.new(self).when quoted_node(right) end + def concat other + Nodes::Concat.new self, other + end + private def grouping_any method_id, others, *extras diff --git a/lib/arel/visitors/depth_first.rb b/lib/arel/visitors/depth_first.rb index 2f71455580..fb21fb1e70 100644 --- a/lib/arel/visitors/depth_first.rb +++ b/lib/arel/visitors/depth_first.rb @@ -72,6 +72,7 @@ module Arel alias :visit_Arel_Nodes_As :binary alias :visit_Arel_Nodes_Assignment :binary alias :visit_Arel_Nodes_Between :binary + alias :visit_Arel_Nodes_Concat :binary alias :visit_Arel_Nodes_DeleteStatement :binary alias :visit_Arel_Nodes_DoesNotMatch :binary alias :visit_Arel_Nodes_Equality :binary diff --git a/lib/arel/visitors/dot.rb b/lib/arel/visitors/dot.rb index e0c02d717a..da75423523 100644 --- a/lib/arel/visitors/dot.rb +++ b/lib/arel/visitors/dot.rb @@ -176,6 +176,7 @@ module Arel alias :visit_Arel_Nodes_As :binary alias :visit_Arel_Nodes_Assignment :binary alias :visit_Arel_Nodes_Between :binary + alias :visit_Arel_Nodes_Concat :binary alias :visit_Arel_Nodes_DoesNotMatch :binary alias :visit_Arel_Nodes_Equality :binary alias :visit_Arel_Nodes_GreaterThan :binary diff --git a/lib/arel/visitors/mysql.rb b/lib/arel/visitors/mysql.rb index 724e0fc43e..ac3ad7b470 100644 --- a/lib/arel/visitors/mysql.rb +++ b/lib/arel/visitors/mysql.rb @@ -72,6 +72,14 @@ module Arel maybe_visit o.limit, collector end + def visit_Arel_Nodes_Concat o, collector + collector << " CONCAT(" + visit o.left, collector + collector << ", " + visit o.right, collector + collector << ") " + collector + end end end end |