arel_extensions 1.2.17 → 1.2.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +102 -0
- data/Gemfile +10 -10
- data/Rakefile +4 -4
- data/arel_extensions.gemspec +1 -1
- data/gemfiles/rails3.gemfile +9 -9
- data/gemfiles/rails4.gemfile +13 -13
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +13 -13
- data/gemfiles/rails6.gemfile +13 -13
- data/gemfiles/rails6_1.gemfile +30 -0
- data/gemspecs/arel_extensions-v1.gemspec +28 -0
- data/{gemspec_v2 → gemspecs}/arel_extensions-v2.gemspec +0 -0
- data/generate_gems.sh +4 -3
- data/lib/arel_extensions.rb +23 -5
- data/lib/arel_extensions/attributes.rb +0 -0
- data/lib/arel_extensions/boolean_functions.rb +3 -7
- data/lib/arel_extensions/common_sql_functions.rb +0 -2
- data/lib/arel_extensions/comparators.rb +11 -14
- data/lib/arel_extensions/date_duration.rb +4 -5
- data/lib/arel_extensions/insert_manager.rb +16 -17
- data/lib/arel_extensions/math.rb +8 -9
- data/lib/arel_extensions/math_functions.rb +22 -20
- data/lib/arel_extensions/nodes/abs.rb +0 -1
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -1
- data/lib/arel_extensions/nodes/blank.rb +0 -1
- data/lib/arel_extensions/nodes/case.rb +3 -4
- data/lib/arel_extensions/nodes/cast.rb +0 -1
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +0 -1
- data/lib/arel_extensions/nodes/collate.rb +0 -1
- data/lib/arel_extensions/nodes/concat.rb +2 -4
- data/lib/arel_extensions/nodes/date_diff.rb +4 -5
- data/lib/arel_extensions/nodes/duration.rb +0 -1
- data/lib/arel_extensions/nodes/find_in_set.rb +0 -1
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +1 -0
- data/lib/arel_extensions/nodes/formatted_number.rb +0 -1
- data/lib/arel_extensions/nodes/function.rb +8 -5
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +0 -6
- data/lib/arel_extensions/nodes/length.rb +5 -0
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +0 -1
- data/lib/arel_extensions/nodes/log10.rb +1 -2
- data/lib/arel_extensions/nodes/matches.rb +0 -2
- data/lib/arel_extensions/nodes/md5.rb +0 -1
- data/lib/arel_extensions/nodes/power.rb +0 -1
- data/lib/arel_extensions/nodes/rand.rb +0 -1
- data/lib/arel_extensions/nodes/repeat.rb +0 -2
- data/lib/arel_extensions/nodes/replace.rb +0 -2
- data/lib/arel_extensions/nodes/round.rb +0 -1
- data/lib/arel_extensions/nodes/soundex.rb +0 -1
- data/lib/arel_extensions/nodes/std.rb +4 -5
- data/lib/arel_extensions/nodes/substring.rb +0 -1
- data/lib/arel_extensions/nodes/sum.rb +0 -0
- data/lib/arel_extensions/nodes/then.rb +0 -0
- data/lib/arel_extensions/nodes/trim.rb +0 -2
- data/lib/arel_extensions/nodes/union.rb +0 -2
- data/lib/arel_extensions/nodes/union_all.rb +0 -2
- data/lib/arel_extensions/nodes/wday.rb +0 -4
- data/lib/arel_extensions/null_functions.rb +3 -5
- data/lib/arel_extensions/predications.rb +2 -3
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +0 -2
- data/lib/arel_extensions/string_functions.rb +30 -23
- data/lib/arel_extensions/tasks.rb +1 -1
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors.rb +68 -60
- data/lib/arel_extensions/visitors/convert_format.rb +37 -0
- data/lib/arel_extensions/visitors/ibm_db.rb +4 -11
- data/lib/arel_extensions/visitors/mssql.rb +50 -45
- data/lib/arel_extensions/visitors/mysql.rb +63 -65
- data/lib/arel_extensions/visitors/oracle.rb +50 -57
- data/lib/arel_extensions/visitors/oracle12.rb +1 -14
- data/lib/arel_extensions/visitors/postgresql.rb +39 -34
- data/lib/arel_extensions/visitors/sqlite.rb +23 -18
- data/lib/arel_extensions/visitors/to_sql.rb +58 -48
- data/test/arelx_test_helper.rb +0 -2
- data/test/database.yml +2 -0
- data/test/real_db_test.rb +26 -41
- data/test/support/fake_record.rb +1 -1
- data/test/test_comparators.rb +0 -4
- data/test/visitors/test_bulk_insert_oracle.rb +0 -1
- data/test/visitors/test_bulk_insert_sqlite.rb +0 -2
- data/test/visitors/test_oracle.rb +1 -2
- data/test/visitors/test_to_sql.rb +16 -25
- data/test/with_ar/all_agnostic_test.rb +140 -139
- data/test/with_ar/insert_agnostic_test.rb +0 -2
- data/test/with_ar/test_bulk_sqlite.rb +0 -4
- data/test/with_ar/test_math_sqlite.rb +4 -8
- data/test/with_ar/test_string_mysql.rb +1 -5
- data/test/with_ar/test_string_sqlite.rb +1 -5
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +8 -4
@@ -1,7 +1,6 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class Union < Arel::Nodes::Union
|
4
|
-
|
5
4
|
def initialize left,right
|
6
5
|
return super(left,right)
|
7
6
|
end
|
@@ -18,6 +17,5 @@ module ArelExtensions
|
|
18
17
|
Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
19
18
|
end
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class UnionAll < Arel::Nodes::UnionAll
|
4
|
-
|
5
4
|
def initialize left,right
|
6
5
|
return super(left,right)
|
7
6
|
end
|
@@ -14,6 +13,5 @@ module ArelExtensions
|
|
14
13
|
Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
15
14
|
end
|
16
15
|
end
|
17
|
-
|
18
16
|
end
|
19
17
|
end
|
@@ -3,23 +3,21 @@ require 'arel_extensions/nodes/is_null'
|
|
3
3
|
|
4
4
|
module ArelExtensions
|
5
5
|
module NullFunctions
|
6
|
-
|
7
|
-
#ISNULL function lets you return an alternative value when an expression is NULL.
|
6
|
+
# ISNULL function lets you return an alternative value when an expression is NULL.
|
8
7
|
def is_null
|
9
8
|
ArelExtensions::Nodes::IsNull.new [self]
|
10
9
|
end
|
11
10
|
|
12
|
-
#ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
|
11
|
+
# ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
|
13
12
|
def is_not_null
|
14
13
|
ArelExtensions::Nodes::IsNotNull.new [self]
|
15
14
|
end
|
16
15
|
|
17
16
|
# returns the first non-null expr in the expression list. You must specify at least two expressions.
|
18
|
-
#If all occurrences of expr evaluate to null, then the function returns null.
|
17
|
+
# If all occurrences of expr evaluate to null, then the function returns null.
|
19
18
|
def coalesce *args
|
20
19
|
args.unshift(self)
|
21
20
|
ArelExtensions::Nodes::Coalesce.new args
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Predications
|
3
|
-
|
4
3
|
def when right, expression = nil
|
5
4
|
ArelExtensions::Nodes::Case.new(self).when(right,expression)
|
6
5
|
end
|
@@ -21,7 +20,7 @@ module ArelExtensions
|
|
21
20
|
ArelExtensions::Nodes::Cast.new([self,right])
|
22
21
|
end
|
23
22
|
|
24
|
-
def in(*other) #In should handle nil element in the Array
|
23
|
+
def in(*other) # In should handle nil element in the Array
|
25
24
|
other = other.first if other.length <= 1
|
26
25
|
case other
|
27
26
|
when Range
|
@@ -49,7 +48,7 @@ module ArelExtensions
|
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
def not_in(*other) #In should handle nil element in the Array
|
51
|
+
def not_in(*other) # In should handle nil element in the Array
|
53
52
|
other = other.first if other.length <= 1
|
54
53
|
case other
|
55
54
|
when Range
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'arel_extensions/nodes/concat' #if Arel::VERSION.to_i < 7
|
1
|
+
require 'arel_extensions/nodes/concat' # if Arel::VERSION.to_i < 7
|
2
2
|
require 'arel_extensions/nodes/length'
|
3
3
|
require 'arel_extensions/nodes/locate'
|
4
4
|
require 'arel_extensions/nodes/substring'
|
@@ -19,19 +19,26 @@ require 'arel_extensions/nodes/md5'
|
|
19
19
|
|
20
20
|
module ArelExtensions
|
21
21
|
module StringFunctions
|
22
|
-
|
23
|
-
#*FindInSet function .......
|
22
|
+
# *FindInSet function .......
|
24
23
|
def &(other)
|
25
24
|
ArelExtensions::Nodes::FindInSet.new [other, self]
|
26
25
|
end
|
27
26
|
|
28
|
-
#LENGTH function returns the length of the value in a text field.
|
27
|
+
# LENGTH function returns the length (bytewise) of the value in a text field.
|
29
28
|
def length
|
30
|
-
ArelExtensions::Nodes::Length.new
|
29
|
+
ArelExtensions::Nodes::Length.new self, true
|
30
|
+
end
|
31
|
+
|
32
|
+
def byte_length
|
33
|
+
ArelExtensions::Nodes::Length.new self, true
|
34
|
+
end
|
35
|
+
|
36
|
+
def char_length
|
37
|
+
ArelExtensions::Nodes::Length.new self, false
|
31
38
|
end
|
32
39
|
|
33
|
-
#LOCATE function returns the first starting position of a string in another string.
|
34
|
-
#If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
|
40
|
+
# LOCATE function returns the first starting position of a string in another string.
|
41
|
+
# If string1 or string2 is NULL then it returns NULL. If string1 not found in string2 then it returns 0.
|
35
42
|
def locate val
|
36
43
|
ArelExtensions::Nodes::Locate.new [self, val]
|
37
44
|
end
|
@@ -51,7 +58,7 @@ module ArelExtensions
|
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
54
|
-
#SOUNDEX function returns a character string containing the phonetic representation of char.
|
61
|
+
# SOUNDEX function returns a character string containing the phonetic representation of char.
|
55
62
|
def soundex
|
56
63
|
ArelExtensions::Nodes::Soundex.new [self]
|
57
64
|
end
|
@@ -64,18 +71,18 @@ module ArelExtensions
|
|
64
71
|
grouping_any :imatches, others, escape
|
65
72
|
end
|
66
73
|
|
67
|
-
# def grouping_any method, others, *extra
|
68
|
-
# puts "*******************"
|
69
|
-
# puts method
|
70
|
-
# puts others.inspect
|
71
|
-
# puts extra.inspect
|
72
|
-
# puts "-------------------"
|
73
|
-
# res = super(method,others,*extra)
|
74
|
-
# puts res.to_sql
|
75
|
-
# puts res.inspect
|
76
|
-
# puts "*******************"
|
77
|
-
# res
|
78
|
-
# end
|
74
|
+
# def grouping_any method, others, *extra
|
75
|
+
# puts "*******************"
|
76
|
+
# puts method
|
77
|
+
# puts others.inspect
|
78
|
+
# puts extra.inspect
|
79
|
+
# puts "-------------------"
|
80
|
+
# res = super(method,others,*extra)
|
81
|
+
# puts res.to_sql
|
82
|
+
# puts res.inspect
|
83
|
+
# puts "*******************"
|
84
|
+
# res
|
85
|
+
# end
|
79
86
|
|
80
87
|
def imatches_all others, escape = nil
|
81
88
|
grouping_all :imatches, others, escape, escape
|
@@ -117,7 +124,7 @@ module ArelExtensions
|
|
117
124
|
ArelExtensions::Nodes::Collate.new(self,option,ai,ci)
|
118
125
|
end
|
119
126
|
|
120
|
-
#REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
|
127
|
+
# REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
|
121
128
|
def replace pattern, substitute
|
122
129
|
if pattern.is_a? Regexp
|
123
130
|
ArelExtensions::Nodes::RegexpReplace.new self, pattern, substitute
|
@@ -134,7 +141,7 @@ module ArelExtensions
|
|
134
141
|
ArelExtensions::Nodes::Concat.new [self, other]
|
135
142
|
end
|
136
143
|
|
137
|
-
#concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
|
144
|
+
# concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
|
138
145
|
def group_concat(sep = nil, *orders, group: nil, order: nil)
|
139
146
|
if orders.present?
|
140
147
|
warn("Warning : ArelExtensions: group_concat: you should now use the kwarg 'order' to specify an order in the group_concat.")
|
@@ -149,7 +156,7 @@ module ArelExtensions
|
|
149
156
|
ArelExtensions::Nodes::GroupConcat.new(self, sep, group: group, order: (order || order_tabs))
|
150
157
|
end
|
151
158
|
|
152
|
-
#Function returns a string after removing left, right or the both prefixes or suffixes int argument
|
159
|
+
# Function returns a string after removing left, right or the both prefixes or suffixes int argument
|
153
160
|
def trim other = ' '
|
154
161
|
ArelExtensions::Nodes::Trim.new [self, other]
|
155
162
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :arel_extensions do
|
2
2
|
desc 'Install DB functions into current DB'
|
3
|
-
task :
|
3
|
+
task install_functions: :environment do
|
4
4
|
@env_db = if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx") || (RUBY_PLATFORM == 'java')) # not supported
|
5
5
|
(RUBY_PLATFORM == 'java' ? "jdbc-sqlite" : 'sqlite')
|
6
6
|
else
|
@@ -1,81 +1,89 @@
|
|
1
|
+
require 'arel_extensions/visitors/convert_format'
|
1
2
|
require 'arel_extensions/visitors/to_sql'
|
2
3
|
require 'arel_extensions/visitors/mysql'
|
3
|
-
require 'arel_extensions/visitors/oracle'
|
4
|
-
require 'arel_extensions/visitors/oracle12'
|
5
4
|
require 'arel_extensions/visitors/postgresql'
|
6
5
|
require 'arel_extensions/visitors/sqlite'
|
7
|
-
require 'arel_extensions/visitors/mssql'
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
if defined?(Arel::Visitors::Oracle)
|
8
|
+
require 'arel_extensions/visitors/oracle'
|
9
|
+
require 'arel_extensions/visitors/oracle12'
|
10
|
+
end
|
11
|
+
|
12
|
+
if defined?(Arel::Visitors::MSSQL)
|
13
|
+
require 'arel_extensions/visitors/mssql'
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
class Arel::Visitors::MSSQL
|
16
|
+
include ArelExtensions::Visitors::MSSQL
|
17
|
+
|
18
|
+
alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
|
19
|
+
def visit_Arel_Nodes_As o, collector
|
20
|
+
if o.left.is_a?(Arel::Nodes::Binary)
|
21
|
+
collector << '('
|
22
|
+
collector = visit o.left, collector
|
23
|
+
collector << ')'
|
24
|
+
else
|
25
|
+
collector = visit o.left, collector
|
26
|
+
end
|
27
|
+
collector << " AS ["
|
28
|
+
collector = visit o.right, collector
|
29
|
+
collector << "]"
|
30
|
+
collector
|
20
31
|
end
|
21
|
-
collector << " AS ["
|
22
|
-
collector = visit o.right, collector
|
23
|
-
collector << "]"
|
24
|
-
collector
|
25
|
-
end
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
alias_method(:old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement) rescue nil
|
34
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
35
|
+
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
36
|
+
o = o.dup
|
37
|
+
o.orders = []
|
38
|
+
end
|
39
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
32
40
|
end
|
33
|
-
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
34
41
|
end
|
35
|
-
end
|
36
42
|
|
37
|
-
begin
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
begin
|
44
|
+
require 'arel_sqlserver'
|
45
|
+
if Arel::VERSION.to_i == 6
|
46
|
+
if Arel::Visitors::VISITORS['sqlserver'] && Arel::Visitors::VISITORS['sqlserver'] != Arel::Visitors::MSSQL
|
47
|
+
Arel::Visitors::VISITORS['sqlserver'].class_eval do
|
48
|
+
include ArelExtensions::Visitors::MSSQL
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
alias_method(:old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement) rescue nil
|
51
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
52
|
+
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
53
|
+
o = o.dup
|
54
|
+
o.orders = []
|
55
|
+
end
|
56
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
49
57
|
end
|
50
|
-
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
51
|
-
end
|
52
58
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
|
60
|
+
def visit_Arel_Nodes_As o, collector
|
61
|
+
if o.left.is_a?(Arel::Nodes::Binary)
|
62
|
+
collector << '('
|
63
|
+
collector = visit o.left, collector
|
64
|
+
collector << ')'
|
65
|
+
else
|
66
|
+
collector = visit o.left, collector
|
67
|
+
end
|
68
|
+
collector << " AS ["
|
69
|
+
collector = visit o.right, collector
|
70
|
+
collector << "]"
|
71
|
+
collector
|
61
72
|
end
|
62
|
-
collector << " AS ["
|
63
|
-
collector = visit o.right, collector
|
64
|
-
collector << "]"
|
65
|
-
collector
|
66
|
-
end
|
67
73
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@connection.schema_cache.
|
73
|
-
|
74
|
+
alias_method(:old_primary_Key_From_Table, :primary_Key_From_Table) rescue nil
|
75
|
+
def primary_Key_From_Table t
|
76
|
+
return unless t
|
77
|
+
|
78
|
+
column_name = @connection.schema_cache.primary_keys(t.name) ||
|
79
|
+
@connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)
|
80
|
+
column_name ? t[column_name] : nil
|
81
|
+
end
|
74
82
|
end
|
75
83
|
end
|
76
84
|
end
|
77
|
-
end
|
78
85
|
rescue LoadError
|
79
|
-
rescue => e
|
80
|
-
|
86
|
+
rescue => e
|
87
|
+
e
|
88
|
+
end
|
81
89
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ArelExtensions
|
2
|
+
module Visitors
|
3
|
+
# Convert date format in strftime syntax to whatever the RDBMs
|
4
|
+
# wants, based on the table of conversion +mapping+.
|
5
|
+
def self.strftime_to_format format, mapping
|
6
|
+
@mapping_regexps ||= {}
|
7
|
+
@mapping_regexps[mapping] ||=
|
8
|
+
Regexp.new(
|
9
|
+
mapping
|
10
|
+
.keys
|
11
|
+
.map{|k| Regexp.escape(k)}
|
12
|
+
.join('|')
|
13
|
+
)
|
14
|
+
|
15
|
+
regexp = @mapping_regexps[mapping]
|
16
|
+
s = StringScanner.new format
|
17
|
+
res = StringIO.new
|
18
|
+
while !s.eos?
|
19
|
+
res <<
|
20
|
+
case
|
21
|
+
when s.scan(regexp)
|
22
|
+
if v = mapping[s.matched]
|
23
|
+
v
|
24
|
+
else
|
25
|
+
# Should never happen.
|
26
|
+
s.matched
|
27
|
+
end
|
28
|
+
when s.scan(/[^%]+/)
|
29
|
+
s.matched
|
30
|
+
when s.scan(/./)
|
31
|
+
s.matched
|
32
|
+
end
|
33
|
+
end
|
34
|
+
res.string
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Visitors
|
3
3
|
class Arel::Visitors::IBM_DB
|
4
|
-
|
5
4
|
def visit_ArelExtensions_Nodes_Ceil o, collector
|
6
5
|
collector << "CEILING("
|
7
6
|
collector = visit o.expr, collector
|
@@ -12,14 +11,13 @@ module ArelExtensions
|
|
12
11
|
def visit_ArelExtensions_Nodes_Trim o, collector
|
13
12
|
collector << "LTRIM(RTRIM("
|
14
13
|
o.expressions.each_with_index { |arg, i|
|
15
|
-
collector <<
|
14
|
+
collector << COMMA if i != 0
|
16
15
|
collector = visit arg, collector
|
17
16
|
}
|
18
17
|
collector << "))"
|
19
18
|
collector
|
20
19
|
end
|
21
20
|
|
22
|
-
|
23
21
|
def visit_ArelExtensions_Nodes_DateDiff o, collector
|
24
22
|
collector << "DAY("
|
25
23
|
collector = visit o.left, collector
|
@@ -33,9 +31,8 @@ module ArelExtensions
|
|
33
31
|
collector
|
34
32
|
end
|
35
33
|
|
36
|
-
|
37
34
|
def visit_ArelExtensions_Nodes_Duration o, collector
|
38
|
-
#visit left for period
|
35
|
+
# visit left for period
|
39
36
|
if o.left == "d"
|
40
37
|
collector << "DAY("
|
41
38
|
elsif o.left == "m"
|
@@ -45,7 +42,7 @@ module ArelExtensions
|
|
45
42
|
elsif o.left == "y"
|
46
43
|
collector << "YEAR("
|
47
44
|
end
|
48
|
-
#visit right
|
45
|
+
# visit right
|
49
46
|
if o.right.is_a?(Arel::Attributes::Attribute)
|
50
47
|
collector = visit o.right, collector
|
51
48
|
else
|
@@ -55,12 +52,11 @@ module ArelExtensions
|
|
55
52
|
collector
|
56
53
|
end
|
57
54
|
|
58
|
-
|
59
55
|
def visit_ArelExtensions_Nodes_IsNull o, collector
|
60
56
|
collector << "COALESCE("
|
61
57
|
collector = visit o.left, collector
|
62
58
|
collector << ","
|
63
|
-
if(o.right.is_a?(Arel::Attributes::Attribute))
|
59
|
+
if (o.right.is_a?(Arel::Attributes::Attribute))
|
64
60
|
collector = visit o.right, collector
|
65
61
|
else
|
66
62
|
collector << "'#{o.right}'"
|
@@ -68,9 +64,6 @@ module ArelExtensions
|
|
68
64
|
collector << ")"
|
69
65
|
collector
|
70
66
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
67
|
end
|
75
68
|
end
|
76
69
|
end
|