arel_extensions 1.4.2 → 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/.codeclimate.yml +2 -1
- data/.gitignore +6 -7
- data/.rubocop.yml +3 -67
- data/.travis/oracle/download.js +152 -0
- data/.travis/oracle/download.sh +30 -0
- data/.travis/oracle/download_ojdbc.js +116 -0
- data/.travis/oracle/install.sh +34 -0
- data/.travis/setup_accounts.sh +9 -0
- data/.travis/sqlite3/extension-functions.sh +6 -0
- data/.travis.yml +223 -0
- data/Gemfile +28 -2
- data/README.md +90 -239
- data/Rakefile +30 -48
- data/TODO +1 -0
- data/appveyor.yml +22 -60
- data/arel_extensions.gemspec +14 -13
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +29 -0
- data/gemfiles/rails5_0.gemfile +29 -0
- data/gemfiles/rails5_1_4.gemfile +14 -14
- data/gemfiles/rails5_2.gemfile +14 -16
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +21 -21
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -10
- data/lib/arel_extensions/boolean_functions.rb +14 -53
- data/lib/arel_extensions/common_sql_functions.rb +17 -16
- data/lib/arel_extensions/comparators.rb +28 -27
- data/lib/arel_extensions/date_duration.rb +13 -17
- data/lib/arel_extensions/insert_manager.rb +15 -18
- data/lib/arel_extensions/math.rb +53 -55
- data/lib/arel_extensions/math_functions.rb +39 -46
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +2 -1
- data/lib/arel_extensions/nodes/case.rb +19 -20
- data/lib/arel_extensions/nodes/cast.rb +8 -10
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/coalesce.rb +4 -3
- data/lib/arel_extensions/nodes/collate.rb +10 -9
- data/lib/arel_extensions/nodes/concat.rb +18 -9
- data/lib/arel_extensions/nodes/date_diff.rb +26 -42
- 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 -35
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +37 -42
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +39 -52
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +2 -1
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +7 -5
- 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 +5 -3
- data/lib/arel_extensions/nodes/replace.rb +8 -16
- 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 +1 -1
- data/lib/arel_extensions/nodes/trim.rb +6 -4
- data/lib/arel_extensions/nodes/union.rb +8 -5
- data/lib/arel_extensions/nodes/union_all.rb +7 -4
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +5 -19
- data/lib/arel_extensions/predications.rb +43 -44
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +7 -5
- data/lib/arel_extensions/string_functions.rb +29 -59
- data/lib/arel_extensions/tasks.rb +6 -6
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
- data/lib/arel_extensions/visitors/mssql.rb +191 -422
- data/lib/arel_extensions/visitors/mysql.rb +212 -350
- data/lib/arel_extensions/visitors/oracle.rb +178 -220
- data/lib/arel_extensions/visitors/oracle12.rb +31 -18
- data/lib/arel_extensions/visitors/postgresql.rb +173 -256
- data/lib/arel_extensions/visitors/sqlite.rb +126 -140
- data/lib/arel_extensions/visitors/to_sql.rb +237 -298
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +31 -224
- data/test/database.yml +7 -15
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +117 -120
- data/test/support/fake_record.rb +3 -9
- data/test/test_comparators.rb +17 -14
- data/test/visitors/test_bulk_insert_oracle.rb +11 -11
- data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
- data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
- data/test/visitors/test_oracle.rb +55 -55
- data/test/visitors/test_to_sql.rb +226 -419
- data/test/with_ar/all_agnostic_test.rb +366 -711
- data/test/with_ar/insert_agnostic_test.rb +21 -27
- data/test/with_ar/test_bulk_sqlite.rb +16 -17
- data/test/with_ar/test_math_sqlite.rb +26 -26
- data/test/with_ar/test_string_mysql.rb +33 -31
- data/test/with_ar/test_string_sqlite.rb +34 -30
- metadata +34 -43
- data/.github/workflows/publish.yml +0 -29
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -399
- data/CONTRIBUTING.md +0 -102
- data/NEWS.md +0 -89
- data/bin/build +0 -15
- data/bin/compose +0 -6
- data/bin/publish +0 -8
- data/dev/arelx.dockerfile +0 -44
- data/dev/compose.yaml +0 -71
- data/dev/postgres.dockerfile +0 -5
- data/dev/rbenv +0 -189
- data/gemfiles/rails4_2.gemfile +0 -38
- data/gemfiles/rails5.gemfile +0 -29
- data/gemfiles/rails6.gemfile +0 -33
- data/gemfiles/rails6_1.gemfile +0 -33
- data/gemfiles/rails7.gemfile +0 -33
- data/gemfiles/rails7_1.gemfile +0 -33
- data/gemfiles/rails7_2.gemfile +0 -33
- data/gemspecs/arel_extensions-v1.gemspec +0 -27
- data/gemspecs/arel_extensions-v2.gemspec +0 -27
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/helpers.rb +0 -62
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
- data/lib/arel_extensions/nodes/rollup.rb +0 -36
- data/lib/arel_extensions/nodes/select.rb +0 -10
- 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 -74
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
@@ -1,102 +1,81 @@
|
|
1
|
-
# MSSQL visitors for java and rails ≥ 7 are painful to work with:
|
2
|
-
# requiring the exact path to the visitor is needed even if the
|
3
|
-
# AR adapter was loaded. It's also needed exactly here because:
|
4
|
-
# 1. putting it inside the visitor or anywhere else will not
|
5
|
-
# guarantee its actual loading.
|
6
|
-
# 2. it needs to load before arel_extensions/visitors.
|
7
|
-
if RUBY_PLATFORM == 'java' \
|
8
|
-
&& RUBY_ENGINE == 'jruby' \
|
9
|
-
&& (version = JRUBY_VERSION.split('.').map(&:to_i)) && version[0] == 9 && version[1] >= 4 \
|
10
|
-
&& Gem::Specification.find { |g| g.name == 'jdbc-mssql' }
|
11
|
-
begin
|
12
|
-
require 'arel/visitors/sqlserver'
|
13
|
-
rescue LoadError
|
14
|
-
warn 'arel/visitors/sqlserver not found: MSSQL might not work correctly.'
|
15
|
-
end
|
16
|
-
elsif RUBY_PLATFORM != 'java' \
|
17
|
-
&& Arel::VERSION.to_i < 10 \
|
18
|
-
&& Gem::Specification.find { |g| g.name == 'activerecord-sqlserver-adapter' }
|
19
|
-
begin
|
20
|
-
require 'arel_sqlserver'
|
21
|
-
rescue LoadError
|
22
|
-
warn 'arel_sqlserver not found: SQLServer Visitor might not work correctly.'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require 'arel_extensions/visitors/convert_format'
|
27
1
|
require 'arel_extensions/visitors/to_sql'
|
28
2
|
require 'arel_extensions/visitors/mysql'
|
29
|
-
require 'arel_extensions/visitors/
|
3
|
+
require 'arel_extensions/visitors/oracle'
|
4
|
+
require 'arel_extensions/visitors/oracle12'
|
30
5
|
require 'arel_extensions/visitors/postgresql'
|
31
6
|
require 'arel_extensions/visitors/sqlite'
|
7
|
+
require 'arel_extensions/visitors/mssql'
|
32
8
|
|
33
|
-
|
34
|
-
|
35
|
-
require 'arel_extensions/visitors/oracle12'
|
36
|
-
end
|
37
|
-
|
38
|
-
if defined?(Arel::Visitors::SQLServer)
|
39
|
-
class Arel::Visitors::SQLServer
|
40
|
-
include ArelExtensions::Visitors::MSSQL
|
41
|
-
end
|
42
|
-
end
|
9
|
+
Arel::Visitors::MSSQL.class_eval do
|
10
|
+
include ArelExtensions::Visitors::MSSQL
|
43
11
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
12
|
+
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
13
|
+
def visit_Arel_Nodes_As o, collector
|
14
|
+
if o.left.is_a?(Arel::Nodes::Binary)
|
15
|
+
collector << '('
|
16
|
+
collector = visit o.left, collector
|
17
|
+
collector << ')'
|
18
|
+
else
|
19
|
+
collector = visit o.left, collector
|
48
20
|
end
|
21
|
+
collector << " AS ["
|
22
|
+
collector = visit o.right, collector
|
23
|
+
collector << "]"
|
24
|
+
collector
|
49
25
|
end
|
50
|
-
end
|
51
26
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
def visit_Arel_Nodes_SelectStatement o, collector
|
58
|
-
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
59
|
-
o = o.dup
|
60
|
-
o.orders = []
|
61
|
-
end
|
62
|
-
old_visit_Arel_Nodes_SelectStatement(o, collector)
|
27
|
+
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
28
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
29
|
+
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
30
|
+
o = o.dup
|
31
|
+
o.orders = []
|
63
32
|
end
|
33
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
64
34
|
end
|
65
35
|
end
|
66
36
|
|
67
|
-
|
68
|
-
|
69
|
-
|
37
|
+
begin
|
38
|
+
require 'arel_sqlserver'
|
39
|
+
if Arel::VERSION.to_i == 6
|
40
|
+
if Arel::Visitors::VISITORS['sqlserver'] && Arel::Visitors::VISITORS['sqlserver'] != Arel::Visitors::MSSQL
|
41
|
+
Arel::Visitors::VISITORS['sqlserver'].class_eval do
|
42
|
+
include ArelExtensions::Visitors::MSSQL
|
70
43
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
# The error could be seen by:
|
80
|
-
#
|
81
|
-
# 1. placing the visit_ inside the visitor, or placing it in a module
|
82
|
-
# then including it here.
|
83
|
-
# 2. replacing the `rescue nil` from aliasing trick, and printing the
|
84
|
-
# error.
|
85
|
-
#
|
86
|
-
# It complains that the visit_ does not exist in the module, as if it's
|
87
|
-
# evaluating the module eagerly, instead of lazily like in other versions
|
88
|
-
# of ruby.
|
89
|
-
#
|
90
|
-
# It might be something different, but this is the first thing we should
|
91
|
-
# investigate.
|
44
|
+
alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
|
45
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
46
|
+
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
47
|
+
o = o.dup
|
48
|
+
o.orders = []
|
49
|
+
end
|
50
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
51
|
+
end
|
92
52
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
53
|
+
alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
|
54
|
+
def visit_Arel_Nodes_As o, collector
|
55
|
+
if o.left.is_a?(Arel::Nodes::Binary)
|
56
|
+
collector << '('
|
57
|
+
collector = visit o.left, collector
|
58
|
+
collector << ')'
|
59
|
+
else
|
60
|
+
collector = visit o.left, collector
|
61
|
+
end
|
62
|
+
collector << " AS ["
|
63
|
+
collector = visit o.right, collector
|
64
|
+
collector << "]"
|
65
|
+
collector
|
66
|
+
end
|
67
|
+
|
68
|
+
alias_method :old_primary_Key_From_Table, :primary_Key_From_Table
|
69
|
+
def primary_Key_From_Table t
|
70
|
+
return unless t
|
71
|
+
column_name = @connection.schema_cache.primary_keys(t.name) ||
|
72
|
+
@connection.schema_cache.columns_hash(t.name).first.try(:second).try(:name)
|
73
|
+
column_name ? t[column_name] : nil
|
74
|
+
end
|
98
75
|
end
|
99
|
-
old_visit_Arel_Nodes_SelectStatement(o, collector)
|
100
76
|
end
|
101
77
|
end
|
78
|
+
rescue LoadError
|
79
|
+
rescue => e
|
80
|
+
e
|
102
81
|
end
|
data/lib/arel_extensions.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'arel'
|
2
|
-
require 'base64'
|
3
2
|
|
4
3
|
require 'arel_extensions/railtie' if defined?(Rails::Railtie)
|
5
4
|
|
@@ -8,53 +7,41 @@ require 'arel_extensions/railtie' if defined?(Rails::Railtie)
|
|
8
7
|
# Count|NamedFunction < Function < Arel::Nodes::Node
|
9
8
|
|
10
9
|
# pure Arel internals improvements
|
11
|
-
|
10
|
+
Arel::Nodes::Binary.class_eval do
|
12
11
|
include Arel::AliasPredication
|
13
12
|
include Arel::Expressions
|
14
13
|
end
|
15
14
|
|
16
|
-
|
15
|
+
Arel::Nodes::Casted.class_eval do
|
17
16
|
include Arel::AliasPredication
|
18
|
-
|
19
|
-
# They forget to define hash.
|
20
|
-
if Gem::Version.new(Arel::VERSION) < Gem::Version.new('10.0.0')
|
21
|
-
def hash
|
22
|
-
[self.class, self.val, self.attribute].hash
|
23
|
-
end
|
24
|
-
end
|
25
17
|
end
|
26
18
|
|
27
|
-
|
19
|
+
Arel::Nodes::Unary.class_eval do
|
28
20
|
include Arel::Math
|
29
21
|
include Arel::AliasPredication
|
30
22
|
include Arel::Expressions
|
31
23
|
end
|
32
24
|
|
33
|
-
|
25
|
+
Arel::Nodes::Grouping.class_eval do
|
26
|
+
include Arel::Math
|
27
|
+
include Arel::AliasPredication
|
34
28
|
include Arel::OrderPredications
|
29
|
+
include Arel::Expressions
|
35
30
|
end
|
36
31
|
|
37
|
-
|
38
|
-
def eql? other
|
39
|
-
self.hash.eql? other.hash
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class Arel::Nodes::Function
|
32
|
+
Arel::Nodes::Function.class_eval do
|
44
33
|
include Arel::Math
|
45
34
|
include Arel::Expressions
|
46
35
|
end
|
47
36
|
|
48
|
-
if
|
49
|
-
|
37
|
+
if Arel::VERSION >= "7.1.0"
|
38
|
+
Arel::Nodes::Case.class_eval do
|
50
39
|
include Arel::Math
|
51
40
|
include Arel::Expressions
|
52
41
|
end
|
53
42
|
end
|
54
43
|
|
55
|
-
require 'arel_extensions/helpers'
|
56
44
|
require 'arel_extensions/version'
|
57
|
-
require 'arel_extensions/aliases'
|
58
45
|
require 'arel_extensions/attributes'
|
59
46
|
require 'arel_extensions/visitors'
|
60
47
|
require 'arel_extensions/nodes'
|
@@ -78,117 +65,42 @@ require 'arel_extensions/nodes/case'
|
|
78
65
|
require 'arel_extensions/nodes/soundex'
|
79
66
|
require 'arel_extensions/nodes/cast'
|
80
67
|
require 'arel_extensions/nodes/json'
|
81
|
-
require 'arel_extensions/nodes/rollup'
|
82
|
-
require 'arel_extensions/nodes/select'
|
83
68
|
|
84
|
-
# It seems like the code in lib/arel_extensions/visitors.rb that is supposed
|
85
|
-
# to inject ArelExtension is not enough. Different versions of the sqlserver
|
86
|
-
# adapter behave differently. It doesn't always proc, so we added this for
|
87
|
-
# coverage.
|
88
|
-
if defined?(Arel::Visitors::SQLServer)
|
89
|
-
Arel::Visitors.const_set('MSSQL', Arel::Visitors::SQLServer)
|
90
|
-
require 'arel_extensions/visitors/mssql'
|
91
|
-
class Arel::Visitors::SQLServer
|
92
|
-
include ArelExtensions::Visitors::MSSQL
|
93
|
-
end
|
94
|
-
end
|
95
69
|
|
96
|
-
module Arel
|
97
|
-
def self.column_of table_name, column_name
|
98
|
-
ArelExtensions.column_of(table_name, column_name)
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.duration s, expr
|
102
|
-
ArelExtensions::Nodes::Duration.new("#{s}i", expr)
|
103
|
-
end
|
104
|
-
|
105
|
-
# The FALSE pseudo literal.
|
106
|
-
def self.false
|
107
|
-
Arel::Nodes::Equality.new(1, 0)
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.grouping *v
|
111
|
-
Arel::Nodes::Grouping.new(*v)
|
112
|
-
end
|
113
|
-
|
114
|
-
def self.json *expr
|
115
|
-
ArelExtensions::Nodes::Json.new(
|
116
|
-
if expr.length == 1
|
117
|
-
expr.first
|
118
|
-
else
|
119
|
-
expr
|
120
|
-
end
|
121
|
-
)
|
122
|
-
end
|
123
|
-
|
124
|
-
def self.json_true
|
125
|
-
res = Arel.grouping(Arel.quoted('true'))
|
126
|
-
res.instance_eval {
|
127
|
-
def return_type
|
128
|
-
:boolean
|
129
|
-
end
|
130
|
-
}
|
131
|
-
res
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.json_false
|
135
|
-
res = Arel.grouping(Arel.quoted('false'))
|
136
|
-
res.instance_eval {
|
137
|
-
def return_type
|
138
|
-
:boolean
|
139
|
-
end
|
140
|
-
}
|
141
|
-
res
|
142
|
-
end
|
143
|
-
|
144
|
-
# The NULL literal.
|
145
|
-
def self.null
|
146
|
-
Arel.quoted(nil)
|
147
|
-
end
|
148
|
-
|
149
|
-
def self.quoted *args
|
150
|
-
Arel::Nodes.build_quoted(*args)
|
151
|
-
end
|
152
70
|
|
71
|
+
module Arel
|
153
72
|
def self.rand
|
154
73
|
ArelExtensions::Nodes::Rand.new
|
155
74
|
end
|
156
75
|
|
157
|
-
def self.rollup(*args)
|
158
|
-
Arel::Nodes::RollUp.new(args)
|
159
|
-
end
|
160
|
-
|
161
76
|
def self.shorten s
|
162
77
|
Base64.urlsafe_encode64(Digest::MD5.new.digest(s)).tr('=', '').tr('-', '_')
|
163
78
|
end
|
164
79
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
tmp = Arel.grouping(nil)
|
172
|
-
Arel.grouping v.map{|e| tmp.convert_to_node(e)}
|
80
|
+
def self.json *expr
|
81
|
+
if expr.length == 1
|
82
|
+
ArelExtensions::Nodes::Json.new(expr.first)
|
83
|
+
else
|
84
|
+
ArelExtensions::Nodes::Json.new(expr)
|
85
|
+
end
|
173
86
|
end
|
174
87
|
|
175
|
-
# For instance
|
176
|
-
#
|
177
|
-
# ```
|
178
|
-
# Arel.when(at[field].is_null).then(0).else(1)
|
179
|
-
# ```
|
180
88
|
def self.when condition
|
181
89
|
ArelExtensions::Nodes::Case.new.when(condition)
|
182
90
|
end
|
91
|
+
|
92
|
+
def self.duration s, expr
|
93
|
+
ArelExtensions::Nodes::Duration.new(s.to_s+'i',expr)
|
94
|
+
end
|
95
|
+
|
183
96
|
end
|
184
97
|
|
185
|
-
|
98
|
+
Arel::Attributes::Attribute.class_eval do
|
186
99
|
include Arel::Math
|
187
100
|
include ArelExtensions::Attributes
|
188
101
|
end
|
189
102
|
|
190
|
-
|
191
|
-
include ArelExtensions::Aliases
|
103
|
+
Arel::Nodes::Function.class_eval do
|
192
104
|
include ArelExtensions::Math
|
193
105
|
include ArelExtensions::Comparators
|
194
106
|
include ArelExtensions::DateDuration
|
@@ -197,149 +109,44 @@ class Arel::Nodes::Function
|
|
197
109
|
include ArelExtensions::BooleanFunctions
|
198
110
|
include ArelExtensions::NullFunctions
|
199
111
|
include ArelExtensions::Predications
|
200
|
-
|
201
|
-
alias_method(:old_as, :as) rescue nil
|
202
|
-
def as other
|
203
|
-
res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
|
204
|
-
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
|
205
|
-
self.alias = Arel.sql(other)
|
206
|
-
end
|
207
|
-
res
|
208
|
-
end
|
209
112
|
end
|
210
113
|
|
211
|
-
|
212
|
-
include ArelExtensions::Math
|
213
|
-
include ArelExtensions::Comparators
|
214
|
-
include ArelExtensions::DateDuration
|
215
|
-
include ArelExtensions::MathFunctions
|
216
|
-
include ArelExtensions::NullFunctions
|
217
|
-
include ArelExtensions::StringFunctions
|
218
|
-
include ArelExtensions::Predications
|
219
|
-
end
|
220
|
-
|
221
|
-
class Arel::Nodes::Unary
|
114
|
+
Arel::Nodes::Unary.class_eval do
|
222
115
|
include ArelExtensions::Math
|
223
116
|
include ArelExtensions::Attributes
|
224
117
|
include ArelExtensions::MathFunctions
|
225
118
|
include ArelExtensions::Comparators
|
226
119
|
include ArelExtensions::Predications
|
227
|
-
def eql? other
|
228
|
-
hash == other.hash
|
229
|
-
end
|
230
120
|
end
|
231
121
|
|
232
|
-
|
122
|
+
Arel::Nodes::Binary.class_eval do
|
233
123
|
include ArelExtensions::Math
|
234
124
|
include ArelExtensions::Attributes
|
235
125
|
include ArelExtensions::MathFunctions
|
236
126
|
include ArelExtensions::Comparators
|
237
127
|
include ArelExtensions::BooleanFunctions
|
238
128
|
include ArelExtensions::Predications
|
239
|
-
def eql? other
|
240
|
-
hash == other.hash
|
241
|
-
end
|
242
129
|
end
|
243
130
|
|
244
|
-
|
131
|
+
Arel::Nodes::Equality.class_eval do
|
245
132
|
include ArelExtensions::Comparators
|
246
133
|
include ArelExtensions::DateDuration
|
247
134
|
include ArelExtensions::MathFunctions
|
248
135
|
include ArelExtensions::StringFunctions
|
249
136
|
end
|
250
137
|
|
251
|
-
|
138
|
+
|
139
|
+
Arel::InsertManager.class_eval do
|
252
140
|
include ArelExtensions::InsertManager
|
253
141
|
end
|
254
142
|
|
255
|
-
|
143
|
+
Arel::SelectManager.class_eval do
|
256
144
|
include ArelExtensions::SetFunctions
|
257
145
|
include ArelExtensions::Nodes
|
258
|
-
|
259
|
-
def as table_name
|
260
|
-
Arel::Nodes::TableAlias.new(self, table_name)
|
261
|
-
end
|
262
|
-
|
263
|
-
# Install an alias, if present.
|
264
|
-
def xas table_name
|
265
|
-
if table_name.present?
|
266
|
-
as table_name
|
267
|
-
else
|
268
|
-
self
|
269
|
-
end
|
270
|
-
end
|
271
146
|
end
|
272
147
|
|
273
|
-
|
148
|
+
Arel::Nodes::As.class_eval do
|
274
149
|
include ArelExtensions::Nodes
|
275
150
|
end
|
276
151
|
|
277
|
-
class Arel::Table
|
278
|
-
alias_method(:old_alias, :alias) rescue nil
|
279
|
-
|
280
|
-
# activerecord 7.1 removed the alias. We might need to remove our dependency
|
281
|
-
# on the alias if it proves problematic.
|
282
|
-
if !self.respond_to?(:table_name)
|
283
|
-
alias :table_name :name
|
284
|
-
end
|
285
|
-
|
286
|
-
def alias(name = "#{self.name}_2")
|
287
|
-
if name.present?
|
288
|
-
Arel::Nodes::TableAlias.new(self, name)
|
289
|
-
else
|
290
|
-
self
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
class Arel::Nodes::TableAlias
|
296
|
-
def method_missing(*args)
|
297
|
-
met = args.shift.to_sym
|
298
|
-
if self.relation.respond_to?(met)
|
299
|
-
self.relation.send(met, args)
|
300
|
-
else
|
301
|
-
super(met, *args)
|
302
|
-
end
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
|
307
|
-
class Arel::Attributes::Attribute
|
308
|
-
def to_sql(engine = Arel::Table.engine)
|
309
|
-
collector = Arel::Collectors::SQLString.new
|
310
|
-
collector = engine.connection.visitor.accept self, collector
|
311
|
-
collector.value
|
312
|
-
end
|
313
|
-
|
314
|
-
def rollup
|
315
|
-
Arel::Nodes::RollUp.new([self])
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
class Arel::Nodes::Node
|
320
|
-
def rollup
|
321
|
-
Arel::Nodes::RollUp.new([self])
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
|
-
require 'active_record'
|
326
|
-
if ActiveRecord.version >= Gem::Version.create('7.2')
|
327
|
-
class ActiveRecord::Relation::WhereClause
|
328
|
-
def except_predicates(columns)
|
329
|
-
attrs = columns.extract! { |node| node.is_a?(Arel::Attribute) }
|
330
|
-
non_attrs = columns.extract! { |node| node.is_a?(Arel::Predications) }
|
331
152
|
|
332
|
-
predicates.reject do |node|
|
333
|
-
if !non_attrs.empty? && node.equality? && node.left.is_a?(Arel::Predications)
|
334
|
-
non_attrs.include?(node.left)
|
335
|
-
end || Arel.fetch_attribute(node) do |attr|
|
336
|
-
attrs.find { |v| v.eql? attr } || columns.include?(attr.name.to_s) # 👈 replces
|
337
|
-
# attrs.include?(attr) || columns.include?(attr.name.to_s) # 👈 this
|
338
|
-
#
|
339
|
-
# And that's because our attributes override `==`, so `attrs.include?(attr)` always
|
340
|
-
# passes because it returns an equality node.
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
data/test/database.yml
CHANGED
@@ -8,30 +8,22 @@ jdbc-sqlite:
|
|
8
8
|
timeout: 500
|
9
9
|
mysql:
|
10
10
|
adapter: mysql2
|
11
|
-
database:
|
12
|
-
username:
|
13
|
-
host: 127.0.0.1
|
14
|
-
port: 3306
|
11
|
+
database: arext_test
|
12
|
+
username: travis
|
15
13
|
encoding: utf8
|
16
14
|
jdbc-mysql:
|
17
15
|
adapter: jdbcmysql
|
18
|
-
database:
|
19
|
-
username:
|
16
|
+
database: arext_test
|
17
|
+
username: travis
|
20
18
|
encoding: utf8
|
21
19
|
postgresql:
|
22
20
|
adapter: postgresql
|
23
|
-
database:
|
21
|
+
database: arext_test
|
24
22
|
username: postgres
|
25
|
-
password: secret
|
26
|
-
host: 127.0.0.1
|
27
|
-
port: 5432
|
28
23
|
jdbc-postgresql:
|
29
24
|
adapter: jdbcpostgresql
|
30
|
-
database:
|
25
|
+
database: arext_test
|
31
26
|
username: postgres
|
32
|
-
password: secret
|
33
|
-
host: 127.0.0.1
|
34
|
-
port: 5432
|
35
27
|
oracle:
|
36
28
|
adapter: oracle_enhanced
|
37
29
|
database: xe
|
@@ -45,7 +37,7 @@ jdbc-oracle:
|
|
45
37
|
ibm_db:
|
46
38
|
adapter: ibm_db
|
47
39
|
username: travis
|
48
|
-
database:
|
40
|
+
database: arext_test
|
49
41
|
mssql:
|
50
42
|
adapter: sqlserver
|
51
43
|
host: localhost
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'arel'
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
require 'arel_extensions'
|
8
|
+
|
9
|
+
require 'support/fake_record'
|
10
|
+
Arel::Table.engine = FakeRecord::Base.new
|
11
|
+
|
12
|
+
$arel_silence_type_casting_deprecation = true
|
13
|
+
|
14
|
+
class Object
|
15
|
+
def must_be_like other
|
16
|
+
gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
|
17
|
+
end
|
18
|
+
end
|