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
@@ -19,7 +19,6 @@ module ArelExtensions
|
|
19
19
|
|
20
20
|
class Else < Arel::Nodes::Unary # :nodoc:
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
24
23
|
else
|
25
24
|
class Case < Arel::Nodes::Case
|
@@ -96,9 +95,9 @@ module ArelExtensions
|
|
96
95
|
|
97
96
|
def eql? other
|
98
97
|
self.class == other.class &&
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
self.case == other.case &&
|
99
|
+
self.conditions == other.conditions &&
|
100
|
+
self.default == other.default
|
102
101
|
end
|
103
102
|
alias :== :eql?
|
104
103
|
|
File without changes
|
@@ -11,7 +11,7 @@ module ArelExtensions::Nodes
|
|
11
11
|
else
|
12
12
|
node
|
13
13
|
end
|
14
|
-
}.flatten.reduce([]) { |
|
14
|
+
}.flatten.reduce([]) { |res, b|
|
15
15
|
# concatenate successive literal strings.
|
16
16
|
if b.is_a?(Arel::Nodes::Quoted) && b.expr == ""
|
17
17
|
res
|
@@ -37,7 +37,6 @@ module ArelExtensions::Nodes
|
|
37
37
|
def concat(other)
|
38
38
|
Concat.new(self.expressions + [other])
|
39
39
|
end
|
40
|
-
|
41
40
|
end
|
42
41
|
|
43
42
|
class GroupConcat < AggregateFunction
|
@@ -47,8 +46,7 @@ module ArelExtensions::Nodes
|
|
47
46
|
|
48
47
|
def initialize node, separator = ', ', **opts
|
49
48
|
@separator = convert_to_node(separator)
|
50
|
-
super node, opts
|
49
|
+
super node, **opts
|
51
50
|
end
|
52
|
-
|
53
51
|
end
|
54
52
|
end
|
@@ -2,7 +2,7 @@ require 'date'
|
|
2
2
|
|
3
3
|
module ArelExtensions
|
4
4
|
module Nodes
|
5
|
-
class DateDiff < Function #difference entre colonne date et date string/date
|
5
|
+
class DateDiff < Function # difference entre colonne date et date string/date
|
6
6
|
attr_accessor :left_node_type
|
7
7
|
attr_accessor :right_node_type
|
8
8
|
|
@@ -97,7 +97,7 @@ module ArelExtensions
|
|
97
97
|
v ||= self.expressions.last
|
98
98
|
if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
|
99
99
|
if @date_type == :ruby_date
|
100
|
-
Arel.sql("(INTERVAL '1' DAY) * %s" % v.inspect.to_i
|
100
|
+
Arel.sql("(INTERVAL '1' DAY) * %s" % v.inspect.to_i)
|
101
101
|
else
|
102
102
|
Arel.sql("(INTERVAL '1' SECOND) * %s" % v.to_i)
|
103
103
|
end
|
@@ -150,6 +150,7 @@ module ArelExtensions
|
|
150
150
|
end
|
151
151
|
|
152
152
|
private
|
153
|
+
|
153
154
|
def convert(object)
|
154
155
|
case object
|
155
156
|
when Arel::Attributes::Attribute, Arel::Nodes::Node, ActiveSupport::Duration
|
@@ -166,7 +167,7 @@ module ArelExtensions
|
|
166
167
|
end
|
167
168
|
end
|
168
169
|
|
169
|
-
class DateSub < Function #difference entre colonne date et date string/date
|
170
|
+
class DateSub < Function # difference entre colonne date et date string/date
|
170
171
|
RETURN_TYPE = :integer
|
171
172
|
|
172
173
|
def initialize(expr)
|
@@ -187,8 +188,6 @@ module ArelExtensions
|
|
187
188
|
end
|
188
189
|
end
|
189
190
|
end
|
190
|
-
|
191
191
|
end
|
192
|
-
|
193
192
|
end
|
194
193
|
end
|
@@ -21,7 +21,11 @@ module ArelExtensions
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def as other
|
24
|
-
Arel::Nodes::As.new(self, Arel.sql(other))
|
24
|
+
res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
|
25
|
+
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
|
26
|
+
self.alias = Arel.sql(other)
|
27
|
+
end
|
28
|
+
res
|
25
29
|
end
|
26
30
|
|
27
31
|
def expr
|
@@ -54,8 +58,8 @@ module ArelExtensions
|
|
54
58
|
end
|
55
59
|
when ArelExtensions::Nodes::Function
|
56
60
|
att.return_type
|
57
|
-
# else
|
58
|
-
# nil
|
61
|
+
# else
|
62
|
+
# nil
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
@@ -76,7 +80,7 @@ module ArelExtensions
|
|
76
80
|
when ActiveSupport::Duration
|
77
81
|
Arel.sql(object.to_i)
|
78
82
|
when Array
|
79
|
-
Arel::Nodes::Grouping.new(object.map{|
|
83
|
+
Arel::Nodes::Grouping.new(object.map{|e| convert_to_node(e)})
|
80
84
|
else
|
81
85
|
raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
|
82
86
|
end
|
@@ -161,7 +165,6 @@ module ArelExtensions
|
|
161
165
|
raise(ArgumentError, "#{object.class} cannot be converted to NUMBER arg")
|
162
166
|
end
|
163
167
|
end
|
164
|
-
|
165
168
|
end
|
166
169
|
end
|
167
170
|
end
|
File without changes
|
@@ -63,11 +63,9 @@ module ArelExtensions
|
|
63
63
|
:string
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
67
66
|
end
|
68
67
|
|
69
68
|
class Json < JsonNode
|
70
|
-
|
71
69
|
def initialize *expr
|
72
70
|
@dict =
|
73
71
|
if expr.length == 1
|
@@ -77,7 +75,6 @@ module ArelExtensions
|
|
77
75
|
end
|
78
76
|
super
|
79
77
|
end
|
80
|
-
|
81
78
|
end
|
82
79
|
|
83
80
|
class JsonMerge < JsonNode
|
@@ -102,7 +99,6 @@ module ArelExtensions
|
|
102
99
|
@dict = json
|
103
100
|
@key = convert_to_node(key)
|
104
101
|
end
|
105
|
-
|
106
102
|
end
|
107
103
|
|
108
104
|
class JsonSet < JsonNode
|
@@ -113,8 +109,6 @@ module ArelExtensions
|
|
113
109
|
@key = convert_to_node(key)
|
114
110
|
@value = Json.new(value)
|
115
111
|
end
|
116
|
-
|
117
112
|
end
|
118
|
-
|
119
113
|
end
|
120
114
|
end
|
File without changes
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class IMatches < Arel::Nodes::Matches
|
4
|
-
|
5
4
|
attr_accessor :case_sensitive if Arel::VERSION.to_i < 7
|
6
5
|
|
7
6
|
def initialize(left, right, escape = nil)
|
@@ -26,6 +25,5 @@ module ArelExtensions
|
|
26
25
|
|
27
26
|
class SMatches < IMatches
|
28
27
|
end
|
29
|
-
|
30
28
|
end
|
31
29
|
end
|
@@ -14,7 +14,6 @@ module ArelExtensions
|
|
14
14
|
def +(other)
|
15
15
|
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
16
16
|
end
|
17
|
-
|
18
17
|
end
|
19
18
|
|
20
19
|
class RegexpReplace < Function
|
@@ -32,6 +31,5 @@ module ArelExtensions
|
|
32
31
|
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
36
34
|
end
|
37
35
|
end
|
@@ -4,9 +4,9 @@ module ArelExtensions
|
|
4
4
|
RETURN_TYPE = :number
|
5
5
|
attr_accessor :unbiased_estimator
|
6
6
|
|
7
|
-
def initialize node, opts
|
7
|
+
def initialize node, **opts
|
8
8
|
@unbiased_estimator = opts[:unbiased] ? true : false
|
9
|
-
super node, opts
|
9
|
+
super node, **opts
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -14,11 +14,10 @@ module ArelExtensions
|
|
14
14
|
RETURN_TYPE = :number
|
15
15
|
attr_accessor :unbiased_estimator
|
16
16
|
|
17
|
-
def initialize node, opts
|
17
|
+
def initialize node, **opts
|
18
18
|
@unbiased_estimator = opts[:unbiased] ? true : false
|
19
|
-
super node, opts
|
19
|
+
super node, **opts
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
24
23
|
end
|
File without changes
|
File without changes
|
@@ -13,7 +13,6 @@ module ArelExtensions
|
|
13
13
|
def +(other)
|
14
14
|
return ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
15
15
|
end
|
16
|
-
|
17
16
|
end
|
18
17
|
|
19
18
|
class Ltrim < Trim
|
@@ -23,6 +22,5 @@ module ArelExtensions
|
|
23
22
|
class Rtrim < Trim
|
24
23
|
RETURN_TYPE = :string
|
25
24
|
end
|
26
|
-
|
27
25
|
end
|
28
26
|
end
|