arel_extensions 1.3.2 → 1.3.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 +12 -12
- 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
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'arel_extensions/helpers'
|
2
|
-
|
3
1
|
module ArelExtensions
|
4
2
|
module Visitors
|
5
3
|
class Arel::Visitors::SQLite
|
@@ -16,7 +14,7 @@ module ArelExtensions
|
|
16
14
|
}.freeze
|
17
15
|
|
18
16
|
NUMBER_COMMA_MAPPING = {
|
19
|
-
'fr_FR' => {',' => ' ', '.' =>','}
|
17
|
+
'fr_FR' => {',' => ' ', '.' => ','}
|
20
18
|
}.freeze
|
21
19
|
|
22
20
|
# String functions
|
@@ -33,27 +31,27 @@ module ArelExtensions
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def visit_ArelExtensions_Nodes_AiMatches o, collector
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
collector = visit o.left.ai_collate, collector
|
35
|
+
collector << ' LIKE '
|
36
|
+
collector = visit o.right.ai_collate, collector
|
37
|
+
if o.escape
|
38
|
+
collector << ' ESCAPE '
|
39
|
+
visit o.escape, collector
|
40
|
+
else
|
41
|
+
collector
|
42
|
+
end
|
45
43
|
end
|
46
44
|
|
47
45
|
def visit_ArelExtensions_Nodes_AiIMatches o, collector
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
46
|
+
collector = visit o.left.collate(true, true), collector
|
47
|
+
collector << ' LIKE '
|
48
|
+
collector = visit o.right.collate(true, true), collector
|
49
|
+
if o.escape
|
50
|
+
collector << ' ESCAPE '
|
51
|
+
visit o.escape, collector
|
52
|
+
else
|
53
|
+
collector
|
54
|
+
end
|
57
55
|
end
|
58
56
|
|
59
57
|
def visit_ArelExtensions_Nodes_SMatches o, collector
|
@@ -96,11 +94,11 @@ module ArelExtensions
|
|
96
94
|
|
97
95
|
# Date operations
|
98
96
|
def visit_ArelExtensions_Nodes_DateAdd o, collector
|
99
|
-
collector <<
|
97
|
+
collector << 'date('
|
100
98
|
collector = visit o.expressions.first, collector
|
101
99
|
collector << COMMA
|
102
100
|
collector = visit o.sqlite_value, collector
|
103
|
-
collector <<
|
101
|
+
collector << ')'
|
104
102
|
collector
|
105
103
|
end
|
106
104
|
|
@@ -112,28 +110,28 @@ module ArelExtensions
|
|
112
110
|
collector << ") - strftime('%s', "
|
113
111
|
collector = visit o.right, collector
|
114
112
|
else
|
115
|
-
collector <<
|
113
|
+
collector << 'julianday('
|
116
114
|
collector = visit o.left, collector
|
117
|
-
collector <<
|
115
|
+
collector << ') - julianday('
|
118
116
|
collector = visit o.right, collector
|
119
117
|
end
|
120
|
-
collector <<
|
118
|
+
collector << ')'
|
121
119
|
collector
|
122
120
|
end
|
123
121
|
|
124
122
|
def visit_ArelExtensions_Nodes_Duration o, collector
|
125
123
|
collector << "strftime('#{DATE_MAPPING[o.left]}'#{COMMA}"
|
126
124
|
collector = visit o.right, collector
|
127
|
-
collector <<
|
125
|
+
collector << ')'
|
128
126
|
collector
|
129
127
|
end
|
130
128
|
|
131
129
|
def visit_ArelExtensions_Nodes_Locate o, collector
|
132
|
-
collector <<
|
130
|
+
collector << 'instr('
|
133
131
|
collector = visit o.expr, collector
|
134
132
|
collector << COMMA
|
135
133
|
collector = visit o.right, collector
|
136
|
-
collector <<
|
134
|
+
collector << ')'
|
137
135
|
collector
|
138
136
|
end
|
139
137
|
|
@@ -143,17 +141,17 @@ module ArelExtensions
|
|
143
141
|
collector = visit arg, collector
|
144
142
|
collector << ' || ' unless i == o.expressions.length - 1
|
145
143
|
}
|
146
|
-
collector <<
|
144
|
+
collector << ')'
|
147
145
|
collector
|
148
146
|
end
|
149
147
|
|
150
148
|
def visit_ArelExtensions_Nodes_Substring o, collector
|
151
|
-
collector <<
|
149
|
+
collector << 'SUBSTR('
|
152
150
|
o.expressions.each_with_index { |arg, i|
|
153
151
|
collector << COMMA if i != 0
|
154
152
|
collector = visit arg, collector
|
155
153
|
}
|
156
|
-
collector <<
|
154
|
+
collector << ')'
|
157
155
|
collector
|
158
156
|
end
|
159
157
|
|
@@ -164,32 +162,32 @@ module ArelExtensions
|
|
164
162
|
end
|
165
163
|
|
166
164
|
def visit_ArelExtensions_Nodes_IsNotNull o, collector
|
167
|
-
|
165
|
+
collector = visit o.expr, collector
|
168
166
|
collector << ' IS NOT NULL'
|
169
167
|
collector
|
170
168
|
end
|
171
169
|
|
172
170
|
def visit_ArelExtensions_Nodes_Rand o, collector
|
173
|
-
collector <<
|
171
|
+
collector << 'RANDOM('
|
174
172
|
if o.left != nil && o.right != nil
|
175
173
|
collector = visit o.left, collector
|
176
174
|
collector << COMMA
|
177
175
|
collector = visit o.right, collector
|
178
176
|
end
|
179
|
-
collector <<
|
177
|
+
collector << ')'
|
180
178
|
collector
|
181
179
|
end
|
182
180
|
|
183
181
|
def visit_Arel_Nodes_Regexp o, collector
|
184
182
|
collector = visit o.left, collector
|
185
|
-
collector <<
|
183
|
+
collector << ' REGEXP'
|
186
184
|
collector = visit o.right, collector
|
187
185
|
collector
|
188
186
|
end
|
189
187
|
|
190
188
|
def visit_Arel_Nodes_NotRegexp o, collector
|
191
189
|
collector = visit o.left, collector
|
192
|
-
collector <<
|
190
|
+
collector << ' NOT REGEXP '
|
193
191
|
collector = visit o.right, collector
|
194
192
|
collector
|
195
193
|
end
|
@@ -197,7 +195,7 @@ module ArelExtensions
|
|
197
195
|
def visit_ArelExtensions_Nodes_Wday o, collector
|
198
196
|
collector << "STRFTIME('%w',"
|
199
197
|
collector = visit o.date, collector
|
200
|
-
collector <<
|
198
|
+
collector << ')'
|
201
199
|
collector
|
202
200
|
end
|
203
201
|
|
@@ -210,32 +208,32 @@ module ArelExtensions
|
|
210
208
|
# AS FLOAT
|
211
209
|
# )
|
212
210
|
def visit_ArelExtensions_Nodes_Floor o, collector
|
213
|
-
collector <<
|
211
|
+
collector << 'CAST(CASE WHEN '
|
214
212
|
collector = visit o.left, collector
|
215
|
-
collector <<
|
213
|
+
collector << ' >= 0 THEN CAST('
|
216
214
|
collector = visit o.left, collector
|
217
|
-
collector <<
|
215
|
+
collector << ' AS INT) WHEN CAST('
|
218
216
|
collector = visit o.left, collector
|
219
|
-
collector <<
|
217
|
+
collector << ' AS INT) = '
|
220
218
|
collector = visit o.left, collector
|
221
|
-
collector <<
|
219
|
+
collector << ' THEN CAST('
|
222
220
|
collector = visit o.left, collector
|
223
|
-
collector <<
|
221
|
+
collector << ' AS INT) ELSE CAST(('
|
224
222
|
collector = visit o.left, collector
|
225
|
-
collector <<
|
223
|
+
collector << ' - 1.0) AS INT) END AS FLOAT)'
|
226
224
|
collector
|
227
225
|
end
|
228
226
|
|
229
227
|
def visit_ArelExtensions_Nodes_Ceil o, collector
|
230
|
-
collector <<
|
228
|
+
collector << 'CASE WHEN ROUND('
|
231
229
|
collector = visit o.left, collector
|
232
|
-
collector <<
|
230
|
+
collector << ', 1) > ROUND('
|
233
231
|
collector = visit o.left, collector
|
234
|
-
collector <<
|
232
|
+
collector << ') THEN ROUND('
|
235
233
|
collector = visit o.left, collector
|
236
|
-
collector <<
|
234
|
+
collector << ') + 1 ELSE ROUND('
|
237
235
|
collector = visit o.left, collector
|
238
|
-
collector <<
|
236
|
+
collector << ') END'
|
239
237
|
collector
|
240
238
|
end
|
241
239
|
|
@@ -245,16 +243,16 @@ module ArelExtensions
|
|
245
243
|
collector << 'SELECT '
|
246
244
|
len = row.length - 1
|
247
245
|
row.zip(o.cols).each_with_index { |(value, attr), i|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
end
|
246
|
+
case value
|
247
|
+
when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
|
248
|
+
collector = visit value.as(attr.name), collector
|
249
|
+
else
|
250
|
+
collector << quote(value, attr && column_for(attr)).to_s
|
251
|
+
if idx == 0
|
252
|
+
collector << ' AS '
|
253
|
+
collector << quote(attr.name)
|
257
254
|
end
|
255
|
+
end
|
258
256
|
collector << COMMA unless i == len
|
259
257
|
}
|
260
258
|
collector << ' UNION ALL ' unless idx == o.left.length - 1
|
@@ -267,22 +265,22 @@ module ArelExtensions
|
|
267
265
|
collector << 'SELECT '
|
268
266
|
len = row.length - 1
|
269
267
|
row.zip(o.cols).each_with_index { |(value, attr), i|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
end
|
268
|
+
case value
|
269
|
+
when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
|
270
|
+
collector = visit value.as(attr.name), collector
|
271
|
+
when Integer
|
272
|
+
collector << value.to_s
|
273
|
+
if idx == 0
|
274
|
+
collector << ' AS '
|
275
|
+
collector << quote(attr.name)
|
276
|
+
end
|
277
|
+
else
|
278
|
+
collector << (attr && attr.able_to_type_cast? ? quote(attr.type_cast_for_database(value)) : quote(value).to_s)
|
279
|
+
if idx == 0
|
280
|
+
collector << ' AS '
|
281
|
+
collector << quote(attr.name)
|
285
282
|
end
|
283
|
+
end
|
286
284
|
collector << COMMA unless i == len
|
287
285
|
}
|
288
286
|
collector << ' UNION ALL ' unless idx == o.left.length - 1
|
@@ -298,7 +296,7 @@ module ArelExtensions
|
|
298
296
|
else
|
299
297
|
visit o.left, collector
|
300
298
|
end
|
301
|
-
collector <<
|
299
|
+
collector << ' UNION '
|
302
300
|
collector =
|
303
301
|
if o.right.is_a?(Arel::SelectManager)
|
304
302
|
visit o.right.ast, collector
|
@@ -315,7 +313,7 @@ module ArelExtensions
|
|
315
313
|
else
|
316
314
|
visit o.left, collector
|
317
315
|
end
|
318
|
-
collector <<
|
316
|
+
collector << ' UNION ALL '
|
319
317
|
collector =
|
320
318
|
if o.right.is_a?(Arel::SelectManager)
|
321
319
|
visit o.right.ast, collector
|
@@ -327,23 +325,23 @@ module ArelExtensions
|
|
327
325
|
|
328
326
|
def get_time_converted element
|
329
327
|
if element.is_a?(Time)
|
330
|
-
|
328
|
+
Arel::Nodes::NamedFunction.new('STRFTIME', [element, '%H:%M:%S'])
|
331
329
|
elsif element.is_a?(Arel::Attributes::Attribute)
|
332
|
-
col =
|
330
|
+
col = Arel.column_of(element.relation.table_name, element.name.to_s)
|
333
331
|
if col && (col.type == :time)
|
334
|
-
|
332
|
+
Arel::Nodes::NamedFunction.new('STRFTIME', [element, '%H:%M:%S'])
|
335
333
|
else
|
336
|
-
|
334
|
+
element
|
337
335
|
end
|
338
336
|
else
|
339
|
-
|
337
|
+
element
|
340
338
|
end
|
341
339
|
end
|
342
340
|
|
343
341
|
remove_method(:visit_Arel_Nodes_GreaterThanOrEqual) rescue nil
|
344
342
|
def visit_Arel_Nodes_GreaterThanOrEqual o, collector
|
345
343
|
collector = visit get_time_converted(o.left), collector
|
346
|
-
collector <<
|
344
|
+
collector << ' >= '
|
347
345
|
collector = visit get_time_converted(o.right), collector
|
348
346
|
collector
|
349
347
|
end
|
@@ -351,7 +349,7 @@ module ArelExtensions
|
|
351
349
|
remove_method(:visit_Arel_Nodes_GreaterThan) rescue nil
|
352
350
|
def visit_Arel_Nodes_GreaterThan o, collector
|
353
351
|
collector = visit get_time_converted(o.left), collector
|
354
|
-
collector <<
|
352
|
+
collector << ' > '
|
355
353
|
collector = visit get_time_converted(o.right), collector
|
356
354
|
collector
|
357
355
|
end
|
@@ -359,7 +357,7 @@ module ArelExtensions
|
|
359
357
|
remove_method(:visit_Arel_Nodes_LessThanOrEqual) rescue nil
|
360
358
|
def visit_Arel_Nodes_LessThanOrEqual o, collector
|
361
359
|
collector = visit get_time_converted(o.left), collector
|
362
|
-
collector <<
|
360
|
+
collector << ' <= '
|
363
361
|
collector = visit get_time_converted(o.right), collector
|
364
362
|
collector
|
365
363
|
end
|
@@ -367,7 +365,7 @@ module ArelExtensions
|
|
367
365
|
remove_method(:visit_Arel_Nodes_LessThan) rescue nil
|
368
366
|
def visit_Arel_Nodes_LessThan o, collector
|
369
367
|
collector = visit get_time_converted(o.left), collector
|
370
|
-
collector <<
|
368
|
+
collector << ' < '
|
371
369
|
collector = visit get_time_converted(o.right), collector
|
372
370
|
collector
|
373
371
|
end
|
@@ -389,10 +387,10 @@ module ArelExtensions
|
|
389
387
|
end
|
390
388
|
|
391
389
|
def visit_ArelExtensions_Nodes_FormattedNumber o, collector
|
392
|
-
format = Arel::Nodes::NamedFunction.new('printf',[Arel
|
390
|
+
format = Arel::Nodes::NamedFunction.new('printf', [Arel.quoted(o.original_string), o.left])
|
393
391
|
locale_map = NUMBER_COMMA_MAPPING[o.locale]
|
394
392
|
if locale_map
|
395
|
-
format = format.replace(',',locale_map[',']).replace('.',locale_map['.'])
|
393
|
+
format = format.replace(',', locale_map[',']).replace('.', locale_map['.'])
|
396
394
|
end
|
397
395
|
visit format, collector
|
398
396
|
collector
|