arel_extensions 2.1.2 → 2.1.5
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 +43 -91
- data/.gitignore +7 -6
- data/.rubocop.yml +62 -1
- data/Gemfile +11 -11
- data/README.md +1 -1
- data/Rakefile +4 -4
- data/TODO +0 -1
- data/appveyor.yml +73 -0
- data/arel_extensions.gemspec +11 -11
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +14 -14
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +15 -14
- data/gemfiles/rails6.gemfile +13 -12
- data/gemfiles/rails6_1.gemfile +13 -12
- data/gemfiles/rails7.gemfile +9 -8
- 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 +12 -12
- data/lib/arel_extensions/comparators.rb +14 -14
- data/lib/arel_extensions/date_duration.rb +7 -7
- data/lib/arel_extensions/helpers.rb +19 -16
- data/lib/arel_extensions/insert_manager.rb +1 -1
- data/lib/arel_extensions/math.rb +44 -31
- 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 +5 -5
- 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 +1 -1
- 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 +10 -10
- 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 +0 -0
- 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 +1 -1
- 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 +2 -2
- 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 +1 -1
- data/lib/arel_extensions/nodes/sum.rb +0 -0
- data/lib/arel_extensions/nodes/then.rb +1 -1
- data/lib/arel_extensions/nodes/trim.rb +2 -2
- 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 +20 -20
- data/lib/arel_extensions/visitors/mssql.rb +150 -130
- data/lib/arel_extensions/visitors/mysql.rb +147 -149
- data/lib/arel_extensions/visitors/oracle.rb +141 -135
- data/lib/arel_extensions/visitors/oracle12.rb +16 -16
- data/lib/arel_extensions/visitors/postgresql.rb +147 -139
- data/lib/arel_extensions/visitors/sqlite.rb +85 -87
- data/lib/arel_extensions/visitors/to_sql.rb +146 -148
- data/lib/arel_extensions/visitors.rb +7 -7
- data/lib/arel_extensions.rb +56 -32
- data/test/arelx_test_helper.rb +14 -13
- data/test/database.yml +5 -5
- data/test/real_db_test.rb +81 -81
- data/test/support/fake_record.rb +2 -2
- data/test/test_comparators.rb +5 -5
- data/test/visitors/test_bulk_insert_oracle.rb +5 -5
- data/test/visitors/test_bulk_insert_sqlite.rb +5 -5
- data/test/visitors/test_bulk_insert_to_sql.rb +5 -5
- data/test/visitors/test_oracle.rb +14 -14
- data/test/visitors/test_to_sql.rb +87 -87
- data/test/with_ar/all_agnostic_test.rb +411 -306
- data/test/with_ar/insert_agnostic_test.rb +19 -16
- data/test/with_ar/test_bulk_sqlite.rb +5 -5
- 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 +3 -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
File without changes
|
File without changes
|
File without changes
|
@@ -7,11 +7,11 @@ module ArelExtensions
|
|
7
7
|
tab = expr.map { |arg|
|
8
8
|
convert_to_node(arg)
|
9
9
|
}
|
10
|
-
|
10
|
+
super(tab)
|
11
11
|
end
|
12
12
|
|
13
13
|
def +(other)
|
14
|
-
|
14
|
+
ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -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
|
@@ -7,11 +7,11 @@ module ArelExtensions
|
|
7
7
|
tab = expr.map { |arg|
|
8
8
|
convert_to_node(arg)
|
9
9
|
}
|
10
|
-
|
10
|
+
super(tab)
|
11
11
|
end
|
12
12
|
|
13
13
|
def +(other)
|
14
|
-
|
14
|
+
ArelExtensions::Nodes::Concat.new(self.expressions + [other])
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -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
|
-
|
4
|
+
def initialize left, right
|
5
|
+
super(left, right)
|
6
6
|
end
|
7
7
|
|
8
8
|
def +(other)
|
9
|
-
|
9
|
+
ArelExtensions::Nodes::Union.new(self, other)
|
10
10
|
end
|
11
11
|
|
12
12
|
def union(other)
|
13
|
-
|
13
|
+
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
|
-
|
4
|
+
def initialize left, right
|
5
|
+
super(left, right)
|
6
6
|
end
|
7
7
|
|
8
8
|
def union_all(other)
|
9
|
-
|
9
|
+
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 <<
|
59
|
-
if
|
58
|
+
collector << ','
|
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
|