arel_extensions 1.3.5 → 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 +21 -16
- data/README.md +13 -125
- data/Rakefile +30 -41
- data/TODO +1 -0
- data/appveyor.yml +22 -51
- data/arel_extensions.gemspec +14 -14
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +14 -14
- data/gemfiles/rails5_0.gemfile +14 -14
- 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 -4
- 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 +14 -13
- 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 +16 -16
- 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 -48
- 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 +7 -5
- 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 -58
- 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 +181 -279
- data/lib/arel_extensions/visitors/mysql.rb +210 -280
- data/lib/arel_extensions/visitors/oracle.rb +180 -201
- data/lib/arel_extensions/visitors/oracle12.rb +31 -18
- data/lib/arel_extensions/visitors/postgresql.rb +173 -252
- data/lib/arel_extensions/visitors/sqlite.rb +126 -140
- data/lib/arel_extensions/visitors/to_sql.rb +237 -272
- data/lib/arel_extensions/visitors.rb +59 -75
- data/lib/arel_extensions.rb +31 -159
- data/test/database.yml +7 -15
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +116 -105
- data/test/support/fake_record.rb +3 -3
- 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 +361 -578
- 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 +22 -29
- data/.github/workflows/ruby.yml +0 -341
- data/gemfiles/rails6.gemfile +0 -30
- data/gemfiles/rails6_1.gemfile +0 -30
- data/gemfiles/rails7.gemfile +0 -23
- data/gemspecs/arel_extensions-v1.gemspec +0 -28
- data/gemspecs/arel_extensions-v2.gemspec +0 -28
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/helpers.rb +0 -51
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- 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 -71
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
@@ -1,97 +1,81 @@
|
|
1
|
-
require 'arel_extensions/visitors/convert_format'
|
2
1
|
require 'arel_extensions/visitors/to_sql'
|
3
2
|
require 'arel_extensions/visitors/mysql'
|
3
|
+
require 'arel_extensions/visitors/oracle'
|
4
|
+
require 'arel_extensions/visitors/oracle12'
|
4
5
|
require 'arel_extensions/visitors/postgresql'
|
5
6
|
require 'arel_extensions/visitors/sqlite'
|
7
|
+
require 'arel_extensions/visitors/mssql'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
require 'arel_extensions/visitors/oracle12'
|
10
|
-
end
|
11
|
-
|
12
|
-
if defined?(Arel::Visitors::SQLServer) || defined?(Arel::Visitors::MSSQL)
|
13
|
-
require 'arel_extensions/visitors/mssql'
|
14
|
-
end
|
9
|
+
Arel::Visitors::MSSQL.class_eval do
|
10
|
+
include ArelExtensions::Visitors::MSSQL
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
20
|
+
end
|
21
|
+
collector << " AS ["
|
22
|
+
collector = visit o.right, collector
|
23
|
+
collector << "]"
|
24
|
+
collector
|
19
25
|
end
|
20
|
-
end
|
21
26
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def visit_Arel_Nodes_As o, collector
|
28
|
-
if o.left.is_a?(Arel::Nodes::Binary)
|
29
|
-
collector << '('
|
30
|
-
collector = visit o.left, collector
|
31
|
-
collector << ')'
|
32
|
-
else
|
33
|
-
collector = visit o.left, collector
|
34
|
-
end
|
35
|
-
collector << ' AS ['
|
36
|
-
collector = visit o.right, collector
|
37
|
-
collector << ']'
|
38
|
-
collector
|
39
|
-
end
|
40
|
-
|
41
|
-
alias_method(:old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement) rescue nil
|
42
|
-
def visit_Arel_Nodes_SelectStatement o, collector
|
43
|
-
if !collector.value.blank? && o.limit.blank? && o.offset.blank?
|
44
|
-
o = o.dup
|
45
|
-
o.orders = []
|
46
|
-
end
|
47
|
-
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 = []
|
48
32
|
end
|
33
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
49
34
|
end
|
35
|
+
end
|
50
36
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
57
43
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
old_visit_Arel_Nodes_SelectStatement(o, collector)
|
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 = []
|
65
49
|
end
|
50
|
+
old_visit_Arel_Nodes_SelectStatement(o,collector)
|
51
|
+
end
|
66
52
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
collector << ' AS ['
|
77
|
-
collector = visit o.right, collector
|
78
|
-
collector << ']'
|
79
|
-
collector
|
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
|
80
61
|
end
|
62
|
+
collector << " AS ["
|
63
|
+
collector = visit o.right, collector
|
64
|
+
collector << "]"
|
65
|
+
collector
|
66
|
+
end
|
81
67
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
column_name ? t[column_name] : nil
|
89
|
-
end
|
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
|
90
74
|
end
|
91
75
|
end
|
92
76
|
end
|
77
|
+
end
|
93
78
|
rescue LoadError
|
94
|
-
|
79
|
+
rescue => e
|
95
80
|
e
|
96
|
-
end
|
97
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'
|
@@ -79,55 +66,9 @@ require 'arel_extensions/nodes/soundex'
|
|
79
66
|
require 'arel_extensions/nodes/cast'
|
80
67
|
require 'arel_extensions/nodes/json'
|
81
68
|
|
82
|
-
# It seems like the code in lib/arel_extensions/visitors.rb that is supposed
|
83
|
-
# to inject ArelExtension is not enough. Different versions of the sqlserver
|
84
|
-
# adapter behave differently. It doesn't always proc, so we added this for
|
85
|
-
# coverage.
|
86
|
-
if defined?(Arel::Visitors::SQLServer)
|
87
|
-
Arel::Visitors.const_set('MSSQL', Arel::Visitors::SQLServer)
|
88
|
-
require 'arel_extensions/visitors/mssql'
|
89
|
-
class Arel::Visitors::SQLServer
|
90
|
-
include ArelExtensions::Visitors::MSSQL
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
module Arel
|
95
|
-
def self.column_of table_name, column_name
|
96
|
-
ArelExtensions.column_of(table_name, column_name)
|
97
|
-
end
|
98
69
|
|
99
|
-
def self.duration s, expr
|
100
|
-
ArelExtensions::Nodes::Duration.new("#{s}i", expr)
|
101
|
-
end
|
102
|
-
|
103
|
-
# The FALSE pseudo literal.
|
104
|
-
def self.false
|
105
|
-
Arel::Nodes::Equality.new(1, 0)
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.grouping *v
|
109
|
-
Arel::Nodes::Grouping.new(*v)
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.json *expr
|
113
|
-
ArelExtensions::Nodes::Json.new(
|
114
|
-
if expr.length == 1
|
115
|
-
expr.first
|
116
|
-
else
|
117
|
-
expr
|
118
|
-
end
|
119
|
-
)
|
120
|
-
end
|
121
|
-
|
122
|
-
# The NULL literal.
|
123
|
-
def self.null
|
124
|
-
Arel.quoted(nil)
|
125
|
-
end
|
126
|
-
|
127
|
-
def self.quoted *args
|
128
|
-
Arel::Nodes.build_quoted(*args)
|
129
|
-
end
|
130
70
|
|
71
|
+
module Arel
|
131
72
|
def self.rand
|
132
73
|
ArelExtensions::Nodes::Rand.new
|
133
74
|
end
|
@@ -136,33 +77,30 @@ module Arel
|
|
136
77
|
Base64.urlsafe_encode64(Digest::MD5.new.digest(s)).tr('=', '').tr('-', '_')
|
137
78
|
end
|
138
79
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
tmp = Arel.grouping(nil)
|
146
|
-
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
|
147
86
|
end
|
148
87
|
|
149
|
-
# For instance
|
150
|
-
#
|
151
|
-
# ```
|
152
|
-
# Arel.when(at[field].is_null).then(0).else(1)
|
153
|
-
# ```
|
154
88
|
def self.when condition
|
155
89
|
ArelExtensions::Nodes::Case.new.when(condition)
|
156
90
|
end
|
91
|
+
|
92
|
+
def self.duration s, expr
|
93
|
+
ArelExtensions::Nodes::Duration.new(s.to_s+'i',expr)
|
94
|
+
end
|
95
|
+
|
157
96
|
end
|
158
97
|
|
159
|
-
|
98
|
+
Arel::Attributes::Attribute.class_eval do
|
160
99
|
include Arel::Math
|
161
100
|
include ArelExtensions::Attributes
|
162
101
|
end
|
163
102
|
|
164
|
-
|
165
|
-
include ArelExtensions::Aliases
|
103
|
+
Arel::Nodes::Function.class_eval do
|
166
104
|
include ArelExtensions::Math
|
167
105
|
include ArelExtensions::Comparators
|
168
106
|
include ArelExtensions::DateDuration
|
@@ -171,110 +109,44 @@ class Arel::Nodes::Function
|
|
171
109
|
include ArelExtensions::BooleanFunctions
|
172
110
|
include ArelExtensions::NullFunctions
|
173
111
|
include ArelExtensions::Predications
|
174
|
-
|
175
|
-
alias_method(:old_as, :as) rescue nil
|
176
|
-
def as other
|
177
|
-
res = Arel::Nodes::As.new(self.clone, Arel.sql(other))
|
178
|
-
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new('9.0.0')
|
179
|
-
self.alias = Arel.sql(other)
|
180
|
-
end
|
181
|
-
res
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
class Arel::Nodes::Grouping
|
186
|
-
include ArelExtensions::Math
|
187
|
-
include ArelExtensions::Comparators
|
188
|
-
include ArelExtensions::DateDuration
|
189
|
-
include ArelExtensions::MathFunctions
|
190
|
-
include ArelExtensions::NullFunctions
|
191
|
-
include ArelExtensions::StringFunctions
|
192
|
-
include ArelExtensions::Predications
|
193
112
|
end
|
194
113
|
|
195
|
-
|
114
|
+
Arel::Nodes::Unary.class_eval do
|
196
115
|
include ArelExtensions::Math
|
197
116
|
include ArelExtensions::Attributes
|
198
117
|
include ArelExtensions::MathFunctions
|
199
118
|
include ArelExtensions::Comparators
|
200
119
|
include ArelExtensions::Predications
|
201
|
-
def eql? other
|
202
|
-
hash == other.hash
|
203
|
-
end
|
204
120
|
end
|
205
121
|
|
206
|
-
|
122
|
+
Arel::Nodes::Binary.class_eval do
|
207
123
|
include ArelExtensions::Math
|
208
124
|
include ArelExtensions::Attributes
|
209
125
|
include ArelExtensions::MathFunctions
|
210
126
|
include ArelExtensions::Comparators
|
211
127
|
include ArelExtensions::BooleanFunctions
|
212
128
|
include ArelExtensions::Predications
|
213
|
-
def eql? other
|
214
|
-
hash == other.hash
|
215
|
-
end
|
216
129
|
end
|
217
130
|
|
218
|
-
|
131
|
+
Arel::Nodes::Equality.class_eval do
|
219
132
|
include ArelExtensions::Comparators
|
220
133
|
include ArelExtensions::DateDuration
|
221
134
|
include ArelExtensions::MathFunctions
|
222
135
|
include ArelExtensions::StringFunctions
|
223
136
|
end
|
224
137
|
|
225
|
-
|
138
|
+
|
139
|
+
Arel::InsertManager.class_eval do
|
226
140
|
include ArelExtensions::InsertManager
|
227
141
|
end
|
228
142
|
|
229
|
-
|
143
|
+
Arel::SelectManager.class_eval do
|
230
144
|
include ArelExtensions::SetFunctions
|
231
145
|
include ArelExtensions::Nodes
|
232
|
-
|
233
|
-
def as table_name
|
234
|
-
Arel::Nodes::TableAlias.new(self, table_name)
|
235
|
-
end
|
236
|
-
|
237
|
-
# Install an alias, if present.
|
238
|
-
def xas table_name
|
239
|
-
if table_name.present?
|
240
|
-
as table_name
|
241
|
-
else
|
242
|
-
self
|
243
|
-
end
|
244
|
-
end
|
245
146
|
end
|
246
147
|
|
247
|
-
|
148
|
+
Arel::Nodes::As.class_eval do
|
248
149
|
include ArelExtensions::Nodes
|
249
150
|
end
|
250
151
|
|
251
|
-
class Arel::Table
|
252
|
-
alias_method(:old_alias, :alias) rescue nil
|
253
|
-
def alias(name = "#{self.name}_2")
|
254
|
-
if name.present?
|
255
|
-
Arel::Nodes::TableAlias.new(self, name)
|
256
|
-
else
|
257
|
-
self
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
152
|
|
262
|
-
class Arel::Nodes::TableAlias
|
263
|
-
def method_missing(*args)
|
264
|
-
met = args.shift.to_sym
|
265
|
-
if self.relation.respond_to?(met)
|
266
|
-
self.relation.send(met, args)
|
267
|
-
else
|
268
|
-
super(met, *args)
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
|
274
|
-
class Arel::Attributes::Attribute
|
275
|
-
def to_sql(engine = Arel::Table.engine)
|
276
|
-
collector = Arel::Collectors::SQLString.new
|
277
|
-
collector = engine.connection.visitor.accept self, collector
|
278
|
-
collector.value
|
279
|
-
end
|
280
|
-
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
|