arel_extensions 1.3.1 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -2
- data/.github/workflows/ruby.yml +4 -4
- data/.rubocop.yml +25 -1
- data/Gemfile +10 -10
- data/README.md +24 -4
- data/Rakefile +4 -4
- data/TODO +0 -1
- data/arel_extensions.gemspec +12 -12
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +13 -13
- data/gemfiles/rails5_0.gemfile +12 -12
- data/gemfiles/rails5_1_4.gemfile +12 -12
- data/gemfiles/rails5_2.gemfile +13 -13
- data/gemfiles/rails6.gemfile +11 -11
- data/gemfiles/rails6_1.gemfile +11 -11
- data/gemfiles/rails7.gemfile +7 -7
- data/gemspecs/arel_extensions-v1.gemspec +12 -12
- data/gemspecs/arel_extensions-v2.gemspec +11 -11
- data/init/mssql.sql +0 -0
- data/init/mysql.sql +0 -0
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +0 -0
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +2 -2
- data/lib/arel_extensions/boolean_functions.rb +2 -4
- data/lib/arel_extensions/common_sql_functions.rb +10 -10
- data/lib/arel_extensions/comparators.rb +14 -14
- data/lib/arel_extensions/date_duration.rb +7 -7
- data/lib/arel_extensions/helpers.rb +16 -13
- data/lib/arel_extensions/insert_manager.rb +1 -1
- data/lib/arel_extensions/math.rb +16 -18
- data/lib/arel_extensions/math_functions.rb +18 -18
- data/lib/arel_extensions/nodes/abs.rb +0 -0
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
- data/lib/arel_extensions/nodes/blank.rb +1 -1
- data/lib/arel_extensions/nodes/case.rb +4 -6
- data/lib/arel_extensions/nodes/cast.rb +3 -3
- data/lib/arel_extensions/nodes/ceil.rb +0 -0
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +0 -0
- data/lib/arel_extensions/nodes/collate.rb +9 -9
- data/lib/arel_extensions/nodes/concat.rb +2 -2
- data/lib/arel_extensions/nodes/date_diff.rb +6 -6
- data/lib/arel_extensions/nodes/duration.rb +0 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
- data/lib/arel_extensions/nodes/floor.rb +0 -0
- data/lib/arel_extensions/nodes/format.rb +1 -1
- data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
- data/lib/arel_extensions/nodes/function.rb +21 -21
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +7 -7
- data/lib/arel_extensions/nodes/length.rb +0 -0
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +0 -0
- data/lib/arel_extensions/nodes/log10.rb +0 -0
- data/lib/arel_extensions/nodes/matches.rb +1 -1
- data/lib/arel_extensions/nodes/md5.rb +0 -0
- data/lib/arel_extensions/nodes/power.rb +0 -0
- data/lib/arel_extensions/nodes/rand.rb +0 -0
- data/lib/arel_extensions/nodes/repeat.rb +0 -0
- data/lib/arel_extensions/nodes/replace.rb +2 -2
- data/lib/arel_extensions/nodes/round.rb +0 -0
- data/lib/arel_extensions/nodes/soundex.rb +2 -2
- data/lib/arel_extensions/nodes/std.rb +0 -0
- data/lib/arel_extensions/nodes/substring.rb +0 -0
- 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 -0
- data/lib/arel_extensions/nodes/union.rb +4 -4
- data/lib/arel_extensions/nodes/union_all.rb +3 -3
- data/lib/arel_extensions/nodes/wday.rb +0 -0
- data/lib/arel_extensions/nodes.rb +0 -0
- data/lib/arel_extensions/null_functions.rb +0 -0
- data/lib/arel_extensions/predications.rb +10 -10
- data/lib/arel_extensions/railtie.rb +1 -1
- data/lib/arel_extensions/set_functions.rb +3 -3
- data/lib/arel_extensions/string_functions.rb +8 -8
- data/lib/arel_extensions/tasks.rb +2 -2
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/convert_format.rb +0 -0
- data/lib/arel_extensions/visitors/ibm_db.rb +19 -19
- data/lib/arel_extensions/visitors/mssql.rb +139 -118
- data/lib/arel_extensions/visitors/mysql.rb +145 -144
- data/lib/arel_extensions/visitors/oracle.rb +136 -128
- data/lib/arel_extensions/visitors/oracle12.rb +16 -16
- data/lib/arel_extensions/visitors/postgresql.rb +147 -136
- data/lib/arel_extensions/visitors/sqlite.rb +83 -85
- data/lib/arel_extensions/visitors/to_sql.rb +143 -148
- data/lib/arel_extensions/visitors.rb +7 -7
- data/lib/arel_extensions.rb +46 -32
- data/test/arelx_test_helper.rb +14 -14
- data/test/database.yml +5 -5
- data/test/real_db_test.rb +78 -78
- data/test/support/fake_record.rb +1 -1
- data/test/test_comparators.rb +5 -5
- data/test/visitors/test_bulk_insert_oracle.rb +4 -4
- data/test/visitors/test_bulk_insert_sqlite.rb +4 -4
- data/test/visitors/test_bulk_insert_to_sql.rb +4 -4
- data/test/visitors/test_oracle.rb +14 -14
- data/test/visitors/test_to_sql.rb +82 -82
- data/test/with_ar/all_agnostic_test.rb +415 -313
- data/test/with_ar/insert_agnostic_test.rb +17 -14
- data/test/with_ar/test_bulk_sqlite.rb +4 -4
- data/test/with_ar/test_math_sqlite.rb +12 -12
- data/test/with_ar/test_string_mysql.rb +20 -20
- data/test/with_ar/test_string_sqlite.rb +20 -20
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +2 -9
- data/.travis/oracle/download.js +0 -152
- data/.travis/oracle/download.sh +0 -30
- data/.travis/oracle/download_ojdbc.js +0 -116
- data/.travis/oracle/install.sh +0 -34
- data/.travis/setup_accounts.sh +0 -9
- data/.travis/sqlite3/extension-functions.sh +0 -6
- data/.travis.yml +0 -193
@@ -50,9 +50,9 @@ module ArelExtensions
|
|
50
50
|
v = self.expressions.last
|
51
51
|
if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
|
52
52
|
if @date_type == :date
|
53
|
-
return Arel
|
53
|
+
return Arel.quoted((v.value >= 0 ? '+' : '-') + v.inspect)
|
54
54
|
elsif @date_type == :datetime
|
55
|
-
return Arel
|
55
|
+
return Arel.quoted((v.value >= 0 ? '+' : '-') + v.inspect)
|
56
56
|
end
|
57
57
|
else
|
58
58
|
return v
|
@@ -115,7 +115,7 @@ module ArelExtensions
|
|
115
115
|
v ||= self.expressions.last
|
116
116
|
if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
|
117
117
|
if @date_type == :date
|
118
|
-
v.to_i / (24*3600)
|
118
|
+
v.to_i / (24 * 3600)
|
119
119
|
elsif @date_type == :datetime
|
120
120
|
if v.parts.size == 1
|
121
121
|
# first entry in the dict v.parts; one of [:years, :months, :weeks, :days, :hours, :minutes, :seconds]
|
@@ -155,9 +155,9 @@ module ArelExtensions
|
|
155
155
|
if ArelExtensions::Nodes::Duration === v
|
156
156
|
v.with_interval = true
|
157
157
|
case v.left
|
158
|
-
when 'd','m','y'
|
158
|
+
when 'd', 'm', 'y'
|
159
159
|
Arel.sql('day')
|
160
|
-
when 'h','mn','s'
|
160
|
+
when 'h', 'mn', 's'
|
161
161
|
Arel.sql('second')
|
162
162
|
when /i\z/
|
163
163
|
Arel.sql(ArelExtensions::Visitors::MSSQL::LOADED_VISITOR::DATE_MAPPING[v.left[0..-2]])
|
@@ -179,7 +179,7 @@ module ArelExtensions
|
|
179
179
|
when DateTime, Time, Date
|
180
180
|
raise(ArgumentError, "#{object.class} cannot be converted to Integer")
|
181
181
|
when String
|
182
|
-
Arel
|
182
|
+
Arel.quoted(object)
|
183
183
|
else
|
184
184
|
raise(ArgumentError, "#{object.class} cannot be converted to Integer")
|
185
185
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -10,7 +10,7 @@ module ArelExtensions
|
|
10
10
|
def initialize expr
|
11
11
|
col = expr[0]
|
12
12
|
@iso_format = convert_format(expr[1])
|
13
|
-
@time_zone =
|
13
|
+
@time_zone = expr[2]
|
14
14
|
@col_type = type_of_attribute(col)
|
15
15
|
super [col, convert_to_string_node(@iso_format)]
|
16
16
|
end
|
@@ -3,10 +3,10 @@ module ArelExtensions
|
|
3
3
|
class FormattedNumber < Function
|
4
4
|
RETURN_TYPE = :string
|
5
5
|
|
6
|
-
attr_accessor :locale, :prefix, :suffix, :flags, :scientific_notation, :width
|
6
|
+
attr_accessor :locale, :prefix, :suffix, :flags, :scientific_notation, :width, :precision, :type, :original_string
|
7
7
|
|
8
8
|
def initialize expr
|
9
|
-
# expr[1] = {:
|
9
|
+
# expr[1] = {locale: 'fr_FR', type: "e"/"f"/"d", prefix: "$ ", suffix: " %", flags: " +-#0", width: 5, precision: 6}
|
10
10
|
col = expr.first
|
11
11
|
@locale = expr[1][:locale]
|
12
12
|
@prefix = expr[1][:prefix]
|
@@ -22,14 +22,14 @@ module ArelExtensions
|
|
22
22
|
|
23
23
|
def as other
|
24
24
|
res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
|
25
|
-
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new(
|
25
|
+
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
|
26
26
|
self.alias = Arel.sql(other)
|
27
27
|
end
|
28
28
|
res
|
29
29
|
end
|
30
30
|
|
31
31
|
def expr
|
32
|
-
|
32
|
+
@expressions.first
|
33
33
|
end
|
34
34
|
|
35
35
|
def left
|
@@ -41,17 +41,17 @@ module ArelExtensions
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def ==(other)
|
44
|
-
Arel::Nodes::Equality.new self, Arel
|
44
|
+
Arel::Nodes::Equality.new self, Arel.quoted(other, self)
|
45
45
|
end
|
46
46
|
|
47
47
|
def !=(other)
|
48
|
-
Arel::Nodes::NotEqual.new self, Arel
|
48
|
+
Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
|
49
49
|
end
|
50
50
|
|
51
51
|
def type_of_attribute(att)
|
52
52
|
case att
|
53
53
|
when Arel::Attributes::Attribute
|
54
|
-
|
54
|
+
Arel.column_of(att.relation.table_name, att.name.to_s)&.type || att
|
55
55
|
when ArelExtensions::Nodes::Function
|
56
56
|
att.return_type
|
57
57
|
# else
|
@@ -64,13 +64,13 @@ module ArelExtensions
|
|
64
64
|
when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
|
65
65
|
object
|
66
66
|
when DateTime
|
67
|
-
Arel
|
67
|
+
Arel.quoted(object, self)
|
68
68
|
when Time
|
69
|
-
Arel
|
69
|
+
Arel.quoted(object.strftime('%H:%M:%S'), self)
|
70
70
|
when MBSTRING, String, Symbol
|
71
|
-
Arel
|
71
|
+
Arel.quoted(object.to_s)
|
72
72
|
when Date
|
73
|
-
Arel
|
73
|
+
Arel.quoted(object.to_s, self)
|
74
74
|
when NilClass
|
75
75
|
Arel.sql('NULL')
|
76
76
|
when ActiveSupport::Duration
|
@@ -87,7 +87,7 @@ module ArelExtensions
|
|
87
87
|
when Arel::Nodes::Node
|
88
88
|
object
|
89
89
|
when Integer
|
90
|
-
Arel
|
90
|
+
Arel.quoted(object.to_s)
|
91
91
|
when Arel::Attributes::Attribute
|
92
92
|
case self.type_of_attribute(object)
|
93
93
|
when :date
|
@@ -98,17 +98,17 @@ module ArelExtensions
|
|
98
98
|
object
|
99
99
|
end
|
100
100
|
when DateTime
|
101
|
-
Arel
|
101
|
+
Arel.quoted(object, self)
|
102
102
|
when Time
|
103
|
-
Arel
|
103
|
+
Arel.quoted(object.strftime('%H:%M:%S'), self)
|
104
104
|
when MBSTRING, String
|
105
|
-
Arel
|
105
|
+
Arel.quoted(object.to_s)
|
106
106
|
when Date
|
107
|
-
Arel
|
107
|
+
Arel.quoted(object, self)
|
108
108
|
when NilClass
|
109
109
|
Arel.sql(nil)
|
110
110
|
when ActiveSupport::Duration
|
111
|
-
Arel
|
111
|
+
Arel.quoted(object.to_i.to_s)
|
112
112
|
else
|
113
113
|
raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
|
114
114
|
end
|
@@ -119,11 +119,11 @@ module ArelExtensions
|
|
119
119
|
when Arel::Attributes::Attribute, Arel::Nodes::Node
|
120
120
|
object
|
121
121
|
when DateTime, Time
|
122
|
-
Arel
|
122
|
+
Arel.quoted(Date.new(object.year, object.month, object.day), self)
|
123
123
|
when MBSTRING, String
|
124
|
-
Arel
|
124
|
+
Arel.quoted(Date.parse(object.to_s), self)
|
125
125
|
when Date
|
126
|
-
Arel
|
126
|
+
Arel.quoted(object, self)
|
127
127
|
else
|
128
128
|
raise(ArgumentError, "#{object.class} cannot be converted to Date")
|
129
129
|
end
|
@@ -134,11 +134,11 @@ module ArelExtensions
|
|
134
134
|
when Arel::Attributes::Attribute, Arel::Nodes::Node
|
135
135
|
object
|
136
136
|
when DateTime, Time
|
137
|
-
Arel
|
137
|
+
Arel.quoted(object, self)
|
138
138
|
when MBSTRING, String
|
139
|
-
Arel
|
139
|
+
Arel.quoted(Time.parse(object.to_s), self)
|
140
140
|
when Date
|
141
|
-
Arel
|
141
|
+
Arel.quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
|
142
142
|
else
|
143
143
|
raise(ArgumentError, "#{object.class} cannot be converted to Datetime")
|
144
144
|
end
|
File without changes
|
@@ -11,15 +11,15 @@ module ArelExtensions
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def get key
|
14
|
-
JsonGet.new(self,key)
|
14
|
+
JsonGet.new(self, key)
|
15
15
|
end
|
16
16
|
|
17
17
|
def set key, value
|
18
|
-
JsonSet.new(self,key,value)
|
18
|
+
JsonSet.new(self, key, value)
|
19
19
|
end
|
20
20
|
|
21
21
|
def group as_array = true, orders = nil
|
22
|
-
JsonGroup.new(self,as_array, orders)
|
22
|
+
JsonGroup.new(self, as_array, orders)
|
23
23
|
end
|
24
24
|
|
25
25
|
def hash
|
@@ -32,19 +32,19 @@ module ArelExtensions
|
|
32
32
|
n.dict
|
33
33
|
when Array
|
34
34
|
n.map{|e|
|
35
|
-
|
35
|
+
(e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_json_node(e)
|
36
36
|
}
|
37
37
|
when Hash
|
38
|
-
n.reduce({}){|acc,v|
|
38
|
+
n.reduce({}){|acc, v|
|
39
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
40
|
acc
|
41
41
|
}
|
42
42
|
when String, Numeric, TrueClass, FalseClass
|
43
43
|
convert_to_node(n)
|
44
44
|
when Date
|
45
|
-
convert_to_node(n.strftime(
|
45
|
+
convert_to_node(n.strftime('%Y-%m-%d'))
|
46
46
|
when DateTime, Time
|
47
|
-
convert_to_node(n.strftime(
|
47
|
+
convert_to_node(n.strftime('%Y-%m-%dT%H:%M:%S.%L%:z'))
|
48
48
|
when NilClass
|
49
49
|
Arel.null
|
50
50
|
when Arel::SelectManager
|
File without changes
|
File without changes
|
File without changes
|
@@ -4,7 +4,7 @@ module ArelExtensions
|
|
4
4
|
attr_accessor :case_sensitive if Arel::VERSION.to_i < 7
|
5
5
|
|
6
6
|
def initialize(left, right, escape = nil)
|
7
|
-
r = Arel
|
7
|
+
r = Arel.quoted(right)
|
8
8
|
if Arel::VERSION.to_i < 7 # managed by default in version 7+ (rails 5), so useful for rails 3 & 4
|
9
9
|
super(left, r, escape)
|
10
10
|
@case_sensitive = false
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -8,7 +8,7 @@ module ArelExtensions
|
|
8
8
|
@left = convert_to_node(left)
|
9
9
|
@pattern = convert_to_node(pattern)
|
10
10
|
@substitute = convert_to_node(substitute)
|
11
|
-
super([@left
|
11
|
+
super([@left, @pattern, @substitute])
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -20,7 +20,7 @@ module ArelExtensions
|
|
20
20
|
@left = convert_to_node(left)
|
21
21
|
@pattern = (pattern.is_a?(Regexp) ? pattern : %r[#{pattern}])
|
22
22
|
@substitute = convert_to_node(substitute)
|
23
|
-
super([@left
|
23
|
+
super([@left, @pattern, @substitute])
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
File without changes
|
@@ -7,11 +7,11 @@ module ArelExtensions
|
|
7
7
|
RETURN_TYPE = :string
|
8
8
|
|
9
9
|
def ==(other)
|
10
|
-
Arel::Nodes::Equality.new self, Arel
|
10
|
+
Arel::Nodes::Equality.new self, Arel.quoted(other, self)
|
11
11
|
end
|
12
12
|
|
13
13
|
def !=(other)
|
14
|
-
Arel::Nodes::NotEqual.new self, Arel
|
14
|
+
Arel::Nodes::NotEqual.new self, Arel.quoted(other, self)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class Union < Arel::Nodes::Union
|
4
|
-
def initialize left,right
|
5
|
-
return super(left,right)
|
4
|
+
def initialize left, right
|
5
|
+
return super(left, right)
|
6
6
|
end
|
7
7
|
|
8
8
|
def +(other)
|
9
|
-
return ArelExtensions::Nodes::Union.new(self,other)
|
9
|
+
return ArelExtensions::Nodes::Union.new(self, other)
|
10
10
|
end
|
11
11
|
|
12
12
|
def union(other)
|
13
|
-
return ArelExtensions::Nodes::UnionAll.new(self,other)
|
13
|
+
return ArelExtensions::Nodes::UnionAll.new(self, other)
|
14
14
|
end
|
15
15
|
|
16
16
|
def as other
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Nodes
|
3
3
|
class UnionAll < Arel::Nodes::UnionAll
|
4
|
-
def initialize left,right
|
5
|
-
return super(left,right)
|
4
|
+
def initialize left, right
|
5
|
+
return super(left, right)
|
6
6
|
end
|
7
7
|
|
8
8
|
def union_all(other)
|
9
|
-
return ArelExtensions::Nodes::UnionAll.new(self,other)
|
9
|
+
return ArelExtensions::Nodes::UnionAll.new(self, other)
|
10
10
|
end
|
11
11
|
|
12
12
|
def as other
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module ArelExtensions
|
2
2
|
module Predications
|
3
3
|
def when right, expression = nil
|
4
|
-
ArelExtensions::Nodes::Case.new(self).when(right,expression)
|
4
|
+
ArelExtensions::Nodes::Case.new(self).when(right, expression)
|
5
5
|
end
|
6
6
|
|
7
|
-
def matches(other, escape = nil,case_sensitive = nil)
|
7
|
+
def matches(other, escape = nil, case_sensitive = nil)
|
8
8
|
if Arel::VERSION.to_i < 7
|
9
|
-
Arel::Nodes::Matches.new(self, Arel
|
9
|
+
Arel::Nodes::Matches.new(self, Arel.quoted(other), escape)
|
10
10
|
else
|
11
|
-
Arel::Nodes::Matches.new(self, Arel
|
11
|
+
Arel::Nodes::Matches.new(self, Arel.quoted(other), escape, case_sensitive)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -17,7 +17,7 @@ module ArelExtensions
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def cast right
|
20
|
-
ArelExtensions::Nodes::Cast.new([self,right])
|
20
|
+
ArelExtensions::Nodes::Cast.new([self, right])
|
21
21
|
end
|
22
22
|
|
23
23
|
def in(*other) # In should handle nil element in the Array
|
@@ -72,7 +72,7 @@ module ArelExtensions
|
|
72
72
|
when Arel::SelectManager
|
73
73
|
Arel::Nodes::NotIn.new(self, other.ast)
|
74
74
|
else
|
75
|
-
Arel::Nodes::NotIn.new(self,quoted_node(other))
|
75
|
+
Arel::Nodes::NotIn.new(self, quoted_node(other))
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -81,13 +81,13 @@ module ArelExtensions
|
|
81
81
|
when Arel::Attributes::Attribute, Arel::Nodes::Node, Integer
|
82
82
|
object
|
83
83
|
when DateTime
|
84
|
-
Arel
|
84
|
+
Arel.quoted(object, self)
|
85
85
|
when Time
|
86
|
-
Arel
|
86
|
+
Arel.quoted(object.strftime('%H:%M:%S'), self)
|
87
87
|
when String
|
88
|
-
Arel
|
88
|
+
Arel.quoted(object)
|
89
89
|
when Date
|
90
|
-
Arel
|
90
|
+
Arel.quoted(object.to_s, self)
|
91
91
|
when NilClass
|
92
92
|
Arel.sql('NULL')
|
93
93
|
when ActiveSupport::Duration
|
@@ -4,15 +4,15 @@ require 'arel_extensions/nodes/union_all'
|
|
4
4
|
module ArelExtensions
|
5
5
|
module SetFunctions
|
6
6
|
def +(other)
|
7
|
-
ArelExtensions::Nodes::Union.new(self,other)
|
7
|
+
ArelExtensions::Nodes::Union.new(self, other)
|
8
8
|
end
|
9
9
|
|
10
10
|
def union(other)
|
11
|
-
ArelExtensions::Nodes::Union.new(self,other)
|
11
|
+
ArelExtensions::Nodes::Union.new(self, other)
|
12
12
|
end
|
13
13
|
|
14
14
|
def union_all(other)
|
15
|
-
ArelExtensions::Nodes::UnionAll.new(self,other)
|
15
|
+
ArelExtensions::Nodes::UnionAll.new(self, other)
|
16
16
|
end
|
17
17
|
|
18
18
|
def uniq
|
@@ -101,27 +101,27 @@ module ArelExtensions
|
|
101
101
|
end
|
102
102
|
|
103
103
|
def ai_matches other # accent insensitive & case sensitive
|
104
|
-
ArelExtensions::Nodes::AiMatches.new(self,other)
|
104
|
+
ArelExtensions::Nodes::AiMatches.new(self, other)
|
105
105
|
end
|
106
106
|
|
107
107
|
def ai_imatches other # accent insensitive & case insensitive
|
108
|
-
ArelExtensions::Nodes::AiIMatches.new(self,other)
|
108
|
+
ArelExtensions::Nodes::AiIMatches.new(self, other)
|
109
109
|
end
|
110
110
|
|
111
111
|
def smatches other # accent sensitive & case sensitive
|
112
|
-
ArelExtensions::Nodes::SMatches.new(self,other)
|
112
|
+
ArelExtensions::Nodes::SMatches.new(self, other)
|
113
113
|
end
|
114
114
|
|
115
115
|
def ai_collate
|
116
|
-
ArelExtensions::Nodes::Collate.new(self,nil,true,false)
|
116
|
+
ArelExtensions::Nodes::Collate.new(self, nil, true, false)
|
117
117
|
end
|
118
118
|
|
119
119
|
def ci_collate
|
120
|
-
ArelExtensions::Nodes::Collate.new(self,nil,false,true)
|
120
|
+
ArelExtensions::Nodes::Collate.new(self, nil, false, true)
|
121
121
|
end
|
122
122
|
|
123
|
-
def collate ai = false,ci = false, option = nil
|
124
|
-
ArelExtensions::Nodes::Collate.new(self,option,ai,ci)
|
123
|
+
def collate ai = false, ci = false, option = nil
|
124
|
+
ArelExtensions::Nodes::Collate.new(self, option, ai, ci)
|
125
125
|
end
|
126
126
|
|
127
127
|
# REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.
|
@@ -144,7 +144,7 @@ module ArelExtensions
|
|
144
144
|
# concat elements of a group, separated by sep and ordered by a list of Ascending or Descending
|
145
145
|
def group_concat(sep = nil, *orders, group: nil, order: nil)
|
146
146
|
if orders.present?
|
147
|
-
warn("Warning
|
147
|
+
warn("Warning: ArelExtensions: group_concat: you should now use the kwarg 'order' to specify an order in the group_concat.")
|
148
148
|
end
|
149
149
|
order_tabs = [orders].flatten.map{ |o|
|
150
150
|
if o.is_a?(Arel::Nodes::Ascending) || o.is_a?(Arel::Nodes::Descending)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
namespace :arel_extensions do
|
2
2
|
desc 'Install DB functions into current DB'
|
3
3
|
task install_functions: :environment do
|
4
|
-
@env_db = if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE ==
|
5
|
-
(RUBY_PLATFORM == 'java' ?
|
4
|
+
@env_db = if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx') || (RUBY_PLATFORM == 'java')) # not supported
|
5
|
+
(RUBY_PLATFORM == 'java' ? 'jdbc-sqlite' : 'sqlite')
|
6
6
|
else
|
7
7
|
ENV['DB'] || ActiveRecord::Base.connection.adapter_name
|
8
8
|
end
|
File without changes
|
@@ -2,45 +2,45 @@ module ArelExtensions
|
|
2
2
|
module Visitors
|
3
3
|
class Arel::Visitors::IBM_DB
|
4
4
|
def visit_ArelExtensions_Nodes_Ceil o, collector
|
5
|
-
collector <<
|
5
|
+
collector << 'CEILING('
|
6
6
|
collector = visit o.expr, collector
|
7
|
-
collector <<
|
7
|
+
collector << ')'
|
8
8
|
collector
|
9
9
|
end
|
10
10
|
|
11
11
|
def visit_ArelExtensions_Nodes_Trim o, collector
|
12
|
-
collector <<
|
12
|
+
collector << 'LTRIM(RTRIM('
|
13
13
|
o.expressions.each_with_index { |arg, i|
|
14
14
|
collector << COMMA if i != 0
|
15
15
|
collector = visit arg, collector
|
16
16
|
}
|
17
|
-
collector <<
|
17
|
+
collector << '))'
|
18
18
|
collector
|
19
19
|
end
|
20
20
|
|
21
21
|
def visit_ArelExtensions_Nodes_DateDiff o, collector
|
22
|
-
collector <<
|
22
|
+
collector << 'DAY('
|
23
23
|
collector = visit o.left, collector
|
24
|
-
collector <<
|
24
|
+
collector << ','
|
25
25
|
if o.right.is_a?(Arel::Attributes::Attribute)
|
26
26
|
collector = visit o.right, collector
|
27
27
|
else
|
28
28
|
collector << "'#{o.right}'"
|
29
29
|
end
|
30
|
-
collector <<
|
30
|
+
collector << ')'
|
31
31
|
collector
|
32
32
|
end
|
33
33
|
|
34
34
|
def visit_ArelExtensions_Nodes_Duration o, collector
|
35
35
|
# visit left for period
|
36
|
-
if o.left ==
|
37
|
-
collector <<
|
38
|
-
elsif o.left ==
|
39
|
-
collector <<
|
40
|
-
elsif o.left ==
|
41
|
-
collector <<
|
42
|
-
elsif o.left ==
|
43
|
-
collector <<
|
36
|
+
if o.left == 'd'
|
37
|
+
collector << 'DAY('
|
38
|
+
elsif o.left == 'm'
|
39
|
+
collector << 'MONTH('
|
40
|
+
elsif o.left == 'w'
|
41
|
+
collector << 'WEEK'
|
42
|
+
elsif o.left == 'y'
|
43
|
+
collector << 'YEAR('
|
44
44
|
end
|
45
45
|
# visit right
|
46
46
|
if o.right.is_a?(Arel::Attributes::Attribute)
|
@@ -48,20 +48,20 @@ module ArelExtensions
|
|
48
48
|
else
|
49
49
|
collector << "'#{o.right}'"
|
50
50
|
end
|
51
|
-
collector <<
|
51
|
+
collector << ')'
|
52
52
|
collector
|
53
53
|
end
|
54
54
|
|
55
55
|
def visit_ArelExtensions_Nodes_IsNull o, collector
|
56
|
-
collector <<
|
56
|
+
collector << 'COALESCE('
|
57
57
|
collector = visit o.left, collector
|
58
|
-
collector <<
|
58
|
+
collector << ','
|
59
59
|
if (o.right.is_a?(Arel::Attributes::Attribute))
|
60
60
|
collector = visit o.right, collector
|
61
61
|
else
|
62
62
|
collector << "'#{o.right}'"
|
63
63
|
end
|
64
|
-
collector <<
|
64
|
+
collector << ')'
|
65
65
|
collector
|
66
66
|
end
|
67
67
|
end
|