arel_extensions 1.2.15 → 1.2.23
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/.travis.yml +2 -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 +11 -5
- data/lib/arel_extensions/attributes.rb +0 -0
- data/lib/arel_extensions/boolean_functions.rb +21 -5
- data/lib/arel_extensions/common_sql_functions.rb +2 -4
- 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 +4 -2
- 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 +7 -8
- 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 +27 -1
- data/lib/arel_extensions/nodes/formatted_number.rb +0 -1
- data/lib/arel_extensions/nodes/function.rb +24 -17
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +11 -17
- data/lib/arel_extensions/nodes/length.rb +0 -1
- 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 +5 -6
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +0 -2
- data/lib/arel_extensions/string_functions.rb +21 -22
- 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 +49 -44
- data/lib/arel_extensions/visitors/mysql.rb +65 -67
- data/lib/arel_extensions/visitors/oracle.rb +58 -55
- data/lib/arel_extensions/visitors/oracle12.rb +1 -14
- data/lib/arel_extensions/visitors/postgresql.rb +41 -34
- data/lib/arel_extensions/visitors/sqlite.rb +23 -18
- data/lib/arel_extensions/visitors/to_sql.rb +59 -47
- data/test/arelx_test_helper.rb +0 -2
- data/test/database.yml +2 -0
- data/test/real_db_test.rb +27 -42
- 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 +141 -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
|
|
@@ -14,7 +14,10 @@ module ArelExtensions
|
|
14
14
|
@return_type = :decimal
|
15
15
|
when :number
|
16
16
|
@return_type = :number
|
17
|
-
when 'char', 'varchar', '
|
17
|
+
when 'char', 'varchar', 'nchar', 'nvarchar'
|
18
|
+
@return_type = :string
|
19
|
+
when 'text', :text, 'ntext', :ntext
|
20
|
+
@as_attr = expr[1].to_sym
|
18
21
|
@return_type = :string
|
19
22
|
when :datetime, 'datetime','smalldatetime'
|
20
23
|
@return_type = :datetime
|
@@ -46,7 +49,6 @@ module ArelExtensions
|
|
46
49
|
def return_type
|
47
50
|
@return_type
|
48
51
|
end
|
49
|
-
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
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
|
@@ -157,16 +158,16 @@ module ArelExtensions
|
|
157
158
|
when Integer
|
158
159
|
object.days
|
159
160
|
when DateTime, Time, Date
|
160
|
-
raise(ArgumentError, "#{object.class}
|
161
|
+
raise(ArgumentError, "#{object.class} cannot be converted to Integer")
|
161
162
|
when String
|
162
163
|
Arel::Nodes.build_quoted(object)
|
163
164
|
else
|
164
|
-
raise(ArgumentError, "#{object.class}
|
165
|
+
raise(ArgumentError, "#{object.class} cannot be converted to Integer")
|
165
166
|
end
|
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)
|
@@ -183,12 +184,10 @@ module ArelExtensions
|
|
183
184
|
if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === object
|
184
185
|
object.to_i
|
185
186
|
else
|
186
|
-
raise(ArgumentError, "#{object.class}
|
187
|
+
raise(ArgumentError, "#{object.class} cannot be converted to Number")
|
187
188
|
end
|
188
189
|
end
|
189
190
|
end
|
190
|
-
|
191
191
|
end
|
192
|
-
|
193
192
|
end
|
194
193
|
end
|
@@ -1,15 +1,41 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
|
1
3
|
module ArelExtensions
|
2
4
|
module Nodes
|
3
5
|
class Format < Function
|
4
6
|
RETURN_TYPE = :string
|
5
7
|
|
6
8
|
attr_accessor :col_type, :iso_format
|
9
|
+
|
7
10
|
def initialize expr
|
8
11
|
col = expr.first
|
9
|
-
@iso_format = expr[1]
|
12
|
+
@iso_format = convert_format(expr[1])
|
10
13
|
@col_type = type_of_attribute(col)
|
11
14
|
super [col, convert_to_string_node(@iso_format)]
|
12
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Address portability issues with some of the formats.
|
20
|
+
def convert_format(fmt)
|
21
|
+
s = StringScanner.new fmt
|
22
|
+
res = StringIO.new
|
23
|
+
while !s.eos?
|
24
|
+
res <<
|
25
|
+
case
|
26
|
+
when s.scan(/%D/) then '%m/%d/%y'
|
27
|
+
when s.scan(/%F/) then '%Y-%m-%d'
|
28
|
+
when s.scan(/%R/) then '%H:%M'
|
29
|
+
when s.scan(/%r/) then '%I:%M:%S %p'
|
30
|
+
when s.scan(/%T/) then '%H:%M:%S'
|
31
|
+
when s.scan(/%v/) then '%e-%b-%Y'
|
32
|
+
|
33
|
+
when s.scan(/[^%]+/) then s.matched
|
34
|
+
when s.scan(/./) then s.matched
|
35
|
+
end
|
36
|
+
end
|
37
|
+
res.string
|
38
|
+
end
|
13
39
|
end
|
14
40
|
end
|
15
41
|
end
|
@@ -10,6 +10,10 @@ 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
|
+
|
13
17
|
# overrides as to make new Node like AliasPredication
|
14
18
|
|
15
19
|
def return_type
|
@@ -17,7 +21,11 @@ module ArelExtensions
|
|
17
21
|
end
|
18
22
|
|
19
23
|
def as other
|
20
|
-
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
|
21
29
|
end
|
22
30
|
|
23
31
|
def expr
|
@@ -50,8 +58,8 @@ module ArelExtensions
|
|
50
58
|
end
|
51
59
|
when ArelExtensions::Nodes::Function
|
52
60
|
att.return_type
|
53
|
-
# else
|
54
|
-
# nil
|
61
|
+
# else
|
62
|
+
# nil
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|
@@ -63,7 +71,7 @@ module ArelExtensions
|
|
63
71
|
Arel::Nodes.build_quoted(object, self)
|
64
72
|
when Time
|
65
73
|
Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
|
66
|
-
when String, Symbol
|
74
|
+
when MBSTRING, String, Symbol
|
67
75
|
Arel::Nodes.build_quoted(object.to_s)
|
68
76
|
when Date
|
69
77
|
Arel::Nodes.build_quoted(object.to_s, self)
|
@@ -72,9 +80,9 @@ module ArelExtensions
|
|
72
80
|
when ActiveSupport::Duration
|
73
81
|
Arel.sql(object.to_i)
|
74
82
|
when Array
|
75
|
-
Arel::Nodes::Grouping.new(object.map{|
|
83
|
+
Arel::Nodes::Grouping.new(object.map{|e| convert_to_node(e)})
|
76
84
|
else
|
77
|
-
raise(ArgumentError, "#{object.class}
|
85
|
+
raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
|
78
86
|
end
|
79
87
|
end
|
80
88
|
|
@@ -97,8 +105,8 @@ module ArelExtensions
|
|
97
105
|
Arel::Nodes.build_quoted(object, self)
|
98
106
|
when Time
|
99
107
|
Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
|
100
|
-
when String
|
101
|
-
Arel::Nodes.build_quoted(object)
|
108
|
+
when MBSTRING, String
|
109
|
+
Arel::Nodes.build_quoted(object.to_s)
|
102
110
|
when Date
|
103
111
|
Arel::Nodes.build_quoted(object, self)
|
104
112
|
when NilClass
|
@@ -106,7 +114,7 @@ module ArelExtensions
|
|
106
114
|
when ActiveSupport::Duration
|
107
115
|
Arel::Nodes.build_quoted(object.to_i.to_s)
|
108
116
|
else
|
109
|
-
raise(ArgumentError, "#{object.class}
|
117
|
+
raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
|
110
118
|
end
|
111
119
|
end
|
112
120
|
|
@@ -116,12 +124,12 @@ module ArelExtensions
|
|
116
124
|
object
|
117
125
|
when DateTime, Time
|
118
126
|
Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
|
119
|
-
when String
|
120
|
-
Arel::Nodes.build_quoted(Date.parse(object), self)
|
127
|
+
when MBSTRING, String
|
128
|
+
Arel::Nodes.build_quoted(Date.parse(object.to_s), self)
|
121
129
|
when Date
|
122
130
|
Arel::Nodes.build_quoted(object, self)
|
123
131
|
else
|
124
|
-
raise(ArgumentError, "#{object.class}
|
132
|
+
raise(ArgumentError, "#{object.class} cannot be converted to Date")
|
125
133
|
end
|
126
134
|
end
|
127
135
|
|
@@ -131,12 +139,12 @@ module ArelExtensions
|
|
131
139
|
object
|
132
140
|
when DateTime, Time
|
133
141
|
Arel::Nodes.build_quoted(object, self)
|
134
|
-
when String
|
135
|
-
Arel::Nodes.build_quoted(Time.parse(object), self)
|
142
|
+
when MBSTRING, String
|
143
|
+
Arel::Nodes.build_quoted(Time.parse(object.to_s), self)
|
136
144
|
when Date
|
137
145
|
Arel::Nodes.build_quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
|
138
146
|
else
|
139
|
-
raise(ArgumentError, "#{object.class}
|
147
|
+
raise(ArgumentError, "#{object.class} cannot be converted to Datetime")
|
140
148
|
end
|
141
149
|
end
|
142
150
|
|
@@ -154,10 +162,9 @@ module ArelExtensions
|
|
154
162
|
when NilClass
|
155
163
|
0
|
156
164
|
else
|
157
|
-
raise(ArgumentError, "#{object.class}
|
165
|
+
raise(ArgumentError, "#{object.class} cannot be converted to NUMBER arg")
|
158
166
|
end
|
159
167
|
end
|
160
|
-
|
161
168
|
end
|
162
169
|
end
|
163
170
|
end
|
File without changes
|
@@ -26,20 +26,6 @@ module ArelExtensions
|
|
26
26
|
[@dict].hash
|
27
27
|
end
|
28
28
|
|
29
|
-
end
|
30
|
-
|
31
|
-
class Json < JsonNode
|
32
|
-
|
33
|
-
def initialize *expr
|
34
|
-
@dict =
|
35
|
-
if expr.length == 1
|
36
|
-
convert_to_json_node(expr.first)
|
37
|
-
else
|
38
|
-
expr.map{|e| convert_to_json_node(e) }
|
39
|
-
end
|
40
|
-
super
|
41
|
-
end
|
42
|
-
|
43
29
|
def convert_to_json_node(n)
|
44
30
|
case n
|
45
31
|
when JsonNode
|
@@ -77,7 +63,18 @@ module ArelExtensions
|
|
77
63
|
:string
|
78
64
|
end
|
79
65
|
end
|
66
|
+
end
|
80
67
|
|
68
|
+
class Json < JsonNode
|
69
|
+
def initialize *expr
|
70
|
+
@dict =
|
71
|
+
if expr.length == 1
|
72
|
+
convert_to_json_node(expr.first)
|
73
|
+
else
|
74
|
+
expr.map{|e| convert_to_json_node(e) }
|
75
|
+
end
|
76
|
+
super
|
77
|
+
end
|
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
|