arel_extensions 1.2.25 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -7
- data/.travis.yml +91 -61
- data/Gemfile +20 -15
- data/README.md +12 -17
- data/Rakefile +29 -40
- data/appveyor.yml +1 -1
- data/arel_extensions.gemspec +3 -3
- data/functions.html +3 -3
- 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/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/postgresql.sql +21 -21
- data/lib/arel_extensions/attributes.rb +1 -0
- data/lib/arel_extensions/boolean_functions.rb +14 -55
- data/lib/arel_extensions/common_sql_functions.rb +8 -7
- data/lib/arel_extensions/comparators.rb +15 -14
- data/lib/arel_extensions/date_duration.rb +5 -4
- data/lib/arel_extensions/insert_manager.rb +16 -17
- data/lib/arel_extensions/math.rb +12 -11
- data/lib/arel_extensions/math_functions.rb +22 -29
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +1 -0
- data/lib/arel_extensions/nodes/case.rb +8 -11
- data/lib/arel_extensions/nodes/cast.rb +2 -4
- 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 +3 -2
- data/lib/arel_extensions/nodes/collate.rb +2 -1
- data/lib/arel_extensions/nodes/concat.rb +16 -7
- data/lib/arel_extensions/nodes/date_diff.rb +13 -10
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -34
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +16 -25
- data/lib/arel_extensions/nodes/json.rb +36 -43
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +1 -0
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +6 -4
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +4 -2
- data/lib/arel_extensions/nodes/replace.rb +6 -22
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +0 -0
- data/lib/arel_extensions/nodes/trim.rb +5 -3
- data/lib/arel_extensions/nodes/union.rb +5 -2
- data/lib/arel_extensions/nodes/union_all.rb +3 -0
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +7 -5
- data/lib/arel_extensions/predications.rb +34 -35
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +4 -2
- data/lib/arel_extensions/string_functions.rb +23 -52
- data/lib/arel_extensions/tasks.rb +5 -5
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +12 -5
- data/lib/arel_extensions/visitors/mssql.rb +58 -64
- data/lib/arel_extensions/visitors/mysql.rb +98 -149
- data/lib/arel_extensions/visitors/oracle.rb +70 -73
- data/lib/arel_extensions/visitors/oracle12.rb +15 -2
- data/lib/arel_extensions/visitors/postgresql.rb +63 -116
- data/lib/arel_extensions/visitors/sqlite.rb +70 -83
- data/lib/arel_extensions/visitors/to_sql.rb +110 -142
- data/lib/arel_extensions/visitors.rb +60 -68
- data/lib/arel_extensions.rb +19 -81
- data/test/database.yml +0 -2
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +43 -28
- data/test/support/fake_record.rb +2 -2
- data/test/test_comparators.rb +12 -9
- data/test/visitors/test_bulk_insert_oracle.rb +8 -8
- data/test/visitors/test_bulk_insert_sqlite.rb +10 -9
- data/test/visitors/test_bulk_insert_to_sql.rb +10 -8
- data/test/visitors/test_oracle.rb +42 -42
- data/test/visitors/test_to_sql.rb +196 -361
- data/test/with_ar/all_agnostic_test.rb +160 -195
- data/test/with_ar/insert_agnostic_test.rb +4 -3
- data/test/with_ar/test_bulk_sqlite.rb +9 -6
- data/test/with_ar/test_math_sqlite.rb +12 -8
- data/test/with_ar/test_string_mysql.rb +11 -5
- data/test/with_ar/test_string_sqlite.rb +12 -4
- metadata +11 -22
- data/.github/workflows/ruby.yml +0 -102
- data/gemfiles/rails6.gemfile +0 -30
- data/gemfiles/rails6_1.gemfile +0 -30
- data/gemspecs/arel_extensions-v1.gemspec +0 -28
- data/gemspecs/arel_extensions-v2.gemspec +0 -28
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/test/arelx_test_helper.rb +0 -26
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
@@ -10,10 +10,6 @@ module ArelExtensions
|
|
10
10
|
|
11
11
|
RETURN_TYPE = :string # by default...
|
12
12
|
|
13
|
-
# Support multibyte string if they are available.
|
14
|
-
MBSTRING =
|
15
|
-
defined?(ActiveSupport::Multibyte::Chars) ? ActiveSupport::Multibyte::Chars : String
|
16
|
-
|
17
13
|
# overrides as to make new Node like AliasPredication
|
18
14
|
|
19
15
|
def return_type
|
@@ -21,11 +17,7 @@ module ArelExtensions
|
|
21
17
|
end
|
22
18
|
|
23
19
|
def as other
|
24
|
-
|
25
|
-
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
|
26
|
-
self.alias = Arel.sql(other)
|
27
|
-
end
|
28
|
-
res
|
20
|
+
Arel::Nodes::As.new(self, Arel.sql(other))
|
29
21
|
end
|
30
22
|
|
31
23
|
def expr
|
@@ -58,8 +50,8 @@ module ArelExtensions
|
|
58
50
|
end
|
59
51
|
when ArelExtensions::Nodes::Function
|
60
52
|
att.return_type
|
61
|
-
|
62
|
-
|
53
|
+
# else
|
54
|
+
# nil
|
63
55
|
end
|
64
56
|
end
|
65
57
|
|
@@ -71,7 +63,7 @@ module ArelExtensions
|
|
71
63
|
Arel::Nodes.build_quoted(object, self)
|
72
64
|
when Time
|
73
65
|
Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
|
74
|
-
when
|
66
|
+
when String, Symbol
|
75
67
|
Arel::Nodes.build_quoted(object.to_s)
|
76
68
|
when Date
|
77
69
|
Arel::Nodes.build_quoted(object.to_s, self)
|
@@ -79,10 +71,8 @@ module ArelExtensions
|
|
79
71
|
Arel.sql('NULL')
|
80
72
|
when ActiveSupport::Duration
|
81
73
|
Arel.sql(object.to_i)
|
82
|
-
when Array
|
83
|
-
Arel::Nodes::Grouping.new(object.map{|e| convert_to_node(e)})
|
84
74
|
else
|
85
|
-
raise(ArgumentError, "#{object.class}
|
75
|
+
raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
|
86
76
|
end
|
87
77
|
end
|
88
78
|
|
@@ -105,8 +95,8 @@ module ArelExtensions
|
|
105
95
|
Arel::Nodes.build_quoted(object, self)
|
106
96
|
when Time
|
107
97
|
Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
|
108
|
-
when
|
109
|
-
Arel::Nodes.build_quoted(object
|
98
|
+
when String
|
99
|
+
Arel::Nodes.build_quoted(object)
|
110
100
|
when Date
|
111
101
|
Arel::Nodes.build_quoted(object, self)
|
112
102
|
when NilClass
|
@@ -114,7 +104,7 @@ module ArelExtensions
|
|
114
104
|
when ActiveSupport::Duration
|
115
105
|
Arel::Nodes.build_quoted(object.to_i.to_s)
|
116
106
|
else
|
117
|
-
raise(ArgumentError, "#{object.class}
|
107
|
+
raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
|
118
108
|
end
|
119
109
|
end
|
120
110
|
|
@@ -124,12 +114,12 @@ module ArelExtensions
|
|
124
114
|
object
|
125
115
|
when DateTime, Time
|
126
116
|
Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
|
127
|
-
when
|
128
|
-
Arel::Nodes.build_quoted(Date.parse(object
|
117
|
+
when String
|
118
|
+
Arel::Nodes.build_quoted(Date.parse(object), self)
|
129
119
|
when Date
|
130
120
|
Arel::Nodes.build_quoted(object, self)
|
131
121
|
else
|
132
|
-
raise(ArgumentError, "#{object.class}
|
122
|
+
raise(ArgumentError, "#{object.class} can not be converted to Date")
|
133
123
|
end
|
134
124
|
end
|
135
125
|
|
@@ -139,12 +129,12 @@ module ArelExtensions
|
|
139
129
|
object
|
140
130
|
when DateTime, Time
|
141
131
|
Arel::Nodes.build_quoted(object, self)
|
142
|
-
when
|
143
|
-
Arel::Nodes.build_quoted(Time.parse(object
|
132
|
+
when String
|
133
|
+
Arel::Nodes.build_quoted(Time.parse(object), self)
|
144
134
|
when Date
|
145
135
|
Arel::Nodes.build_quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
|
146
136
|
else
|
147
|
-
raise(ArgumentError, "#{object.class}
|
137
|
+
raise(ArgumentError, "#{object.class} can not be converted to Datetime")
|
148
138
|
end
|
149
139
|
end
|
150
140
|
|
@@ -162,9 +152,10 @@ module ArelExtensions
|
|
162
152
|
when NilClass
|
163
153
|
0
|
164
154
|
else
|
165
|
-
raise(ArgumentError, "#{object.class}
|
155
|
+
raise(ArgumentError, "#{object.class} can not be converted to NUMBER arg")
|
166
156
|
end
|
167
157
|
end
|
158
|
+
|
168
159
|
end
|
169
160
|
end
|
170
161
|
end
|
@@ -18,7 +18,7 @@ module ArelExtensions
|
|
18
18
|
JsonSet.new(self,key,value)
|
19
19
|
end
|
20
20
|
|
21
|
-
def group as_array = true, orders
|
21
|
+
def group as_array = true, orders= nil
|
22
22
|
JsonGroup.new(self,as_array, orders)
|
23
23
|
end
|
24
24
|
|
@@ -26,55 +26,41 @@ module ArelExtensions
|
|
26
26
|
[@dict].hash
|
27
27
|
end
|
28
28
|
|
29
|
-
def convert_to_json_node(n)
|
30
|
-
case n
|
31
|
-
when JsonNode
|
32
|
-
n.dict
|
33
|
-
when Array
|
34
|
-
n.map{|e|
|
35
|
-
(e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_json_node(e)
|
36
|
-
}
|
37
|
-
when Hash
|
38
|
-
n.reduce({}){|acc,v|
|
39
|
-
acc[convert_to_json_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_json_node(v[1])
|
40
|
-
acc
|
41
|
-
}
|
42
|
-
when String, Numeric, TrueClass, FalseClass
|
43
|
-
convert_to_node(n)
|
44
|
-
when Date
|
45
|
-
convert_to_node(n.strftime("%Y-%m-%d"))
|
46
|
-
when DateTime, Time
|
47
|
-
convert_to_node(n.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
|
48
|
-
when NilClass
|
49
|
-
Arel.sql('null')
|
50
|
-
else
|
51
|
-
convert_to_node(n)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def type_of_node(v)
|
56
|
-
if v.is_a?(Arel::Attributes::Attribute)
|
57
|
-
self.type_of_attribute(v)
|
58
|
-
elsif v.respond_to?(:return_type)
|
59
|
-
v.return_type
|
60
|
-
elsif v.nil?
|
61
|
-
:nil
|
62
|
-
else
|
63
|
-
:string
|
64
|
-
end
|
65
|
-
end
|
66
29
|
end
|
67
30
|
|
68
31
|
class Json < JsonNode
|
32
|
+
|
69
33
|
def initialize *expr
|
70
|
-
|
71
|
-
|
72
|
-
|
34
|
+
if expr.length == 1
|
35
|
+
case expr.first
|
36
|
+
when JsonNode
|
37
|
+
@dict = expr.first.dict
|
38
|
+
when Array
|
39
|
+
@dict = expr.first.map{|e|
|
40
|
+
(e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e)
|
41
|
+
}
|
42
|
+
when Hash
|
43
|
+
@dict = expr.first.inject({}){|acc,v|
|
44
|
+
acc[convert_to_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_node(v[1])
|
45
|
+
acc
|
46
|
+
}
|
47
|
+
when String, Numeric, TrueClass, FalseClass
|
48
|
+
@dict = convert_to_node(expr.first)
|
49
|
+
when NilClass
|
50
|
+
@dict = Arel.sql('null')
|
73
51
|
else
|
74
|
-
expr.
|
52
|
+
if expr.first.is_a?(String) || (expr.first.is_a?(Arel::Attributes::Attribute) && type_of_attribute(expr.first) == :string) || (expr.first.return_type == :string)
|
53
|
+
@dict = convert_to_node(expr.first)
|
54
|
+
else
|
55
|
+
@dict = [convert_to_node(expr.first)]
|
56
|
+
end
|
75
57
|
end
|
58
|
+
else
|
59
|
+
@dict = expr.map{|e| (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e) }
|
60
|
+
end
|
76
61
|
super
|
77
62
|
end
|
63
|
+
|
78
64
|
end
|
79
65
|
|
80
66
|
class JsonMerge < JsonNode
|
@@ -87,7 +73,11 @@ module ArelExtensions
|
|
87
73
|
@dict = as_array ? json : json.dict
|
88
74
|
@as_array = as_array
|
89
75
|
if orders
|
90
|
-
|
76
|
+
if orders.is_a?(Array)
|
77
|
+
@orders = orders
|
78
|
+
else
|
79
|
+
@orders = [orders]
|
80
|
+
end
|
91
81
|
end
|
92
82
|
end
|
93
83
|
end
|
@@ -99,6 +89,7 @@ module ArelExtensions
|
|
99
89
|
@dict = json
|
100
90
|
@key = convert_to_node(key)
|
101
91
|
end
|
92
|
+
|
102
93
|
end
|
103
94
|
|
104
95
|
class JsonSet < JsonNode
|
@@ -109,6 +100,8 @@ module ArelExtensions
|
|
109
100
|
@key = convert_to_node(key)
|
110
101
|
@value = Json.new(value)
|
111
102
|
end
|
103
|
+
|
112
104
|
end
|
105
|
+
|
113
106
|
end
|
114
107
|
end
|
File without changes
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class IMatches < Arel::Nodes::Matches
|
4
|
-
attr_accessor :case_sensitive if Arel::VERSION.to_i < 7
|
5
4
|
|
5
|
+
attr_accessor :case_sensitive if Arel::VERSION.to_i < 7
|
6
|
+
|
6
7
|
def initialize(left, right, escape = nil)
|
7
8
|
r = Arel::Nodes.build_quoted(right)
|
8
9
|
if Arel::VERSION.to_i < 7 # managed by default in version 7+ (rails 5), so useful for rails 3 & 4
|
@@ -16,14 +17,15 @@ module ArelExtensions
|
|
16
17
|
|
17
18
|
class IDoesNotMatch < IMatches
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
class AiMatches < IMatches
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
class AiIMatches < IMatches
|
24
25
|
end
|
25
|
-
|
26
|
+
|
26
27
|
class SMatches < IMatches
|
27
28
|
end
|
29
|
+
|
28
30
|
end
|
29
31
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class Power < Function
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
RETURN_TYPE = :number
|
5
|
+
|
6
|
+
def initialize expr
|
7
|
+
super [convert_to_node(expr.first), convert_to_number(expr[1])]
|
8
|
+
end
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -2,7 +2,7 @@ module ArelExtensions
|
|
2
2
|
module Nodes
|
3
3
|
class Repeat < Function
|
4
4
|
RETURN_TYPE = :string
|
5
|
-
|
5
|
+
|
6
6
|
def initialize expr
|
7
7
|
tab = expr.map { |arg|
|
8
8
|
convert_to_node(arg)
|
@@ -11,8 +11,10 @@ module ArelExtensions
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def +(other)
|
14
|
-
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
14
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
15
15
|
end
|
16
|
+
|
16
17
|
end
|
18
|
+
|
17
19
|
end
|
18
20
|
end
|
@@ -2,34 +2,18 @@ module ArelExtensions
|
|
2
2
|
module Nodes
|
3
3
|
class Replace < Function
|
4
4
|
RETURN_TYPE = :string
|
5
|
-
attr_accessor :left, :pattern, :substitute
|
6
5
|
|
7
|
-
def initialize
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
super(
|
6
|
+
def initialize expr
|
7
|
+
tab = expr.map { |arg|
|
8
|
+
convert_to_node(arg)
|
9
|
+
}
|
10
|
+
return super(tab)
|
12
11
|
end
|
13
12
|
|
14
13
|
def +(other)
|
15
|
-
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
14
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
16
15
|
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class RegexpReplace < Function
|
20
|
-
RETURN_TYPE = :string
|
21
|
-
attr_accessor :left, :pattern, :substitute
|
22
16
|
|
23
|
-
def initialize left, pattern, substitute
|
24
|
-
@left = convert_to_node(left)
|
25
|
-
@pattern = (pattern.is_a?(Regexp) ? pattern : %r[#{pattern}])
|
26
|
-
@substitute = convert_to_node(substitute)
|
27
|
-
super([@left,@pattern,@substitute])
|
28
|
-
end
|
29
|
-
|
30
|
-
def +(other)
|
31
|
-
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
32
|
-
end
|
33
17
|
end
|
34
18
|
end
|
35
19
|
end
|
@@ -4,12 +4,13 @@ module ArelExtensions
|
|
4
4
|
RETURN_TYPE = :number
|
5
5
|
|
6
6
|
def initialize expr
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
if expr && expr.length == 1
|
8
|
+
super [convert_to_node(expr.first)]
|
9
|
+
else
|
10
|
+
super [convert_to_node(expr.first), convert_to_number(expr[1])]
|
11
|
+
end
|
12
12
|
end
|
13
|
+
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module ArelExtensions
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Nodes
|
3
|
+
class Soundex < Function
|
4
|
+
include Arel::Expressions
|
5
|
+
include ArelExtensions::Comparators
|
6
|
+
|
7
|
+
RETURN_TYPE = :string
|
8
|
+
|
9
|
+
def ==(other)
|
10
|
+
Arel::Nodes::Equality.new self, Arel::Nodes.build_quoted(other, self)
|
11
|
+
end
|
6
12
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def !=(other)
|
14
|
-
Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
13
|
+
def !=(other)
|
14
|
+
Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -1,23 +1,26 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
|
-
class Std <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
class Variance < AggregateFunction
|
14
|
-
RETURN_TYPE = :number
|
15
|
-
attr_accessor :unbiased_estimator
|
16
|
-
|
17
|
-
def initialize node, **opts
|
18
|
-
@unbiased_estimator = opts[:unbiased] ? true : false
|
19
|
-
super node, **opts
|
20
|
-
end
|
3
|
+
class Std < Function
|
4
|
+
RETURN_TYPE = :number
|
5
|
+
|
6
|
+
attr_accessor :unbiased_estimator
|
7
|
+
def initialize expr
|
8
|
+
col = expr.first
|
9
|
+
@unbiased_estimator = expr[1]
|
10
|
+
super [col]
|
11
|
+
end
|
21
12
|
end
|
13
|
+
|
14
|
+
class Variance < Function
|
15
|
+
RETURN_TYPE = :number
|
16
|
+
|
17
|
+
attr_accessor :unbiased_estimator
|
18
|
+
def initialize expr
|
19
|
+
col = expr.first
|
20
|
+
@unbiased_estimator = expr[1]
|
21
|
+
super [col]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
22
25
|
end
|
23
26
|
end
|
@@ -1,15 +1,23 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class Substring < Function
|
4
|
-
|
4
|
+
RETURN_TYPE = :string
|
5
|
+
|
6
|
+
def initialize expr
|
7
|
+
tab = [convert_to_node(expr[0]), convert_to_node(expr[1])]
|
8
|
+
if expr[2]
|
9
|
+
tab << convert_to_node(expr[2])
|
10
|
+
# else
|
11
|
+
# tab << expr[0].length
|
12
|
+
end
|
13
|
+
return super(tab)
|
14
|
+
end
|
15
|
+
|
16
|
+
# def +(other)
|
17
|
+
# puts "[Substring] : #{other.inspect} (#{self.expressions.inspect})"
|
18
|
+
# return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
19
|
+
# end
|
5
20
|
|
6
|
-
def initialize expr
|
7
|
-
tab = [convert_to_node(expr[0]), convert_to_node(expr[1])]
|
8
|
-
if expr[2]
|
9
|
-
tab << convert_to_node(expr[2])
|
10
|
-
end
|
11
|
-
return super(tab)
|
12
|
-
end
|
13
21
|
end
|
14
22
|
end
|
15
23
|
end
|
File without changes
|
@@ -2,7 +2,7 @@ module ArelExtensions
|
|
2
2
|
module Nodes
|
3
3
|
class Trim < Function
|
4
4
|
RETURN_TYPE = :string
|
5
|
-
|
5
|
+
|
6
6
|
def initialize expr
|
7
7
|
tab = expr.map { |arg|
|
8
8
|
convert_to_node(arg)
|
@@ -11,16 +11,18 @@ module ArelExtensions
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def +(other)
|
14
|
-
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
14
|
+
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
15
15
|
end
|
16
|
+
|
16
17
|
end
|
17
18
|
|
18
19
|
class Ltrim < Trim
|
19
|
-
|
20
|
+
RETURN_TYPE = :string
|
20
21
|
end
|
21
22
|
|
22
23
|
class Rtrim < Trim
|
23
24
|
RETURN_TYPE = :string
|
24
25
|
end
|
26
|
+
|
25
27
|
end
|
26
28
|
end
|
@@ -1,21 +1,24 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class Union < Arel::Nodes::Union
|
4
|
+
|
4
5
|
def initialize left,right
|
5
6
|
return super(left,right)
|
6
7
|
end
|
7
8
|
|
8
9
|
def +(other)
|
9
|
-
return ArelExtensions::Nodes::Union.new(self,other)
|
10
|
+
return ArelExtensions::Nodes::Union.new(self,other)
|
10
11
|
end
|
11
12
|
|
12
13
|
def union(other)
|
13
|
-
return ArelExtensions::Nodes::UnionAll.new(self,other)
|
14
|
+
return ArelExtensions::Nodes::UnionAll.new(self,other)
|
14
15
|
end
|
15
16
|
|
16
17
|
def as other
|
17
18
|
Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
18
19
|
end
|
19
20
|
end
|
21
|
+
|
20
22
|
end
|
21
23
|
end
|
24
|
+
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class UnionAll < Arel::Nodes::UnionAll
|
4
|
+
|
4
5
|
def initialize left,right
|
5
6
|
return super(left,right)
|
6
7
|
end
|
@@ -13,5 +14,7 @@ module ArelExtensions
|
|
13
14
|
Arel::Nodes::TableAlias.new Arel::Nodes::Grouping.new(self), Arel::Nodes::SqlLiteral.new(other.to_s)
|
14
15
|
end
|
15
16
|
end
|
17
|
+
|
16
18
|
end
|
17
19
|
end
|
20
|
+
|
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'arel_extensions/nodes/function'
|
2
|
-
|
2
|
+
|
@@ -3,21 +3,23 @@ require 'arel_extensions/nodes/is_null'
|
|
3
3
|
|
4
4
|
module ArelExtensions
|
5
5
|
module NullFunctions
|
6
|
-
|
6
|
+
|
7
|
+
#ISNULL function lets you return an alternative value when an expression is NULL.
|
7
8
|
def is_null
|
8
9
|
ArelExtensions::Nodes::IsNull.new [self]
|
9
10
|
end
|
10
|
-
|
11
|
-
#
|
11
|
+
|
12
|
+
#ISNOTNULL function lets you return an alternative value when an expression is NOT NULL.
|
12
13
|
def is_not_null
|
13
14
|
ArelExtensions::Nodes::IsNotNull.new [self]
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
# returns the first non-null expr in the expression list. You must specify at least two expressions.
|
17
|
-
#
|
18
|
+
#If all occurrences of expr evaluate to null, then the function returns null.
|
18
19
|
def coalesce *args
|
19
20
|
args.unshift(self)
|
20
21
|
ArelExtensions::Nodes::Coalesce.new args
|
21
22
|
end
|
23
|
+
|
22
24
|
end
|
23
25
|
end
|