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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -2
  3. data/.github/workflows/ruby.yml +43 -91
  4. data/.gitignore +7 -6
  5. data/.rubocop.yml +62 -1
  6. data/Gemfile +11 -11
  7. data/README.md +1 -1
  8. data/Rakefile +4 -4
  9. data/TODO +0 -1
  10. data/appveyor.yml +73 -0
  11. data/arel_extensions.gemspec +11 -11
  12. data/gemfiles/rails3.gemfile +10 -10
  13. data/gemfiles/rails4.gemfile +14 -14
  14. data/gemfiles/rails5_0.gemfile +13 -13
  15. data/gemfiles/rails5_1_4.gemfile +13 -13
  16. data/gemfiles/rails5_2.gemfile +15 -14
  17. data/gemfiles/rails6.gemfile +13 -12
  18. data/gemfiles/rails6_1.gemfile +13 -12
  19. data/gemfiles/rails7.gemfile +9 -8
  20. data/gemspecs/arel_extensions-v1.gemspec +12 -12
  21. data/gemspecs/arel_extensions-v2.gemspec +11 -11
  22. data/init/mssql.sql +0 -0
  23. data/init/mysql.sql +0 -0
  24. data/init/oracle.sql +0 -0
  25. data/init/postgresql.sql +0 -0
  26. data/init/sqlite.sql +0 -0
  27. data/lib/arel_extensions/attributes.rb +2 -2
  28. data/lib/arel_extensions/boolean_functions.rb +2 -4
  29. data/lib/arel_extensions/common_sql_functions.rb +12 -12
  30. data/lib/arel_extensions/comparators.rb +14 -14
  31. data/lib/arel_extensions/date_duration.rb +7 -7
  32. data/lib/arel_extensions/helpers.rb +19 -16
  33. data/lib/arel_extensions/insert_manager.rb +1 -1
  34. data/lib/arel_extensions/math.rb +44 -31
  35. data/lib/arel_extensions/math_functions.rb +18 -18
  36. data/lib/arel_extensions/nodes/abs.rb +0 -0
  37. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
  38. data/lib/arel_extensions/nodes/blank.rb +1 -1
  39. data/lib/arel_extensions/nodes/case.rb +4 -6
  40. data/lib/arel_extensions/nodes/cast.rb +5 -5
  41. data/lib/arel_extensions/nodes/ceil.rb +0 -0
  42. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  43. data/lib/arel_extensions/nodes/coalesce.rb +1 -1
  44. data/lib/arel_extensions/nodes/collate.rb +9 -9
  45. data/lib/arel_extensions/nodes/concat.rb +2 -2
  46. data/lib/arel_extensions/nodes/date_diff.rb +10 -10
  47. data/lib/arel_extensions/nodes/duration.rb +0 -0
  48. data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
  49. data/lib/arel_extensions/nodes/floor.rb +0 -0
  50. data/lib/arel_extensions/nodes/format.rb +0 -0
  51. data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
  52. data/lib/arel_extensions/nodes/function.rb +21 -21
  53. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  54. data/lib/arel_extensions/nodes/json.rb +7 -7
  55. data/lib/arel_extensions/nodes/length.rb +0 -0
  56. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  57. data/lib/arel_extensions/nodes/locate.rb +1 -1
  58. data/lib/arel_extensions/nodes/log10.rb +0 -0
  59. data/lib/arel_extensions/nodes/matches.rb +1 -1
  60. data/lib/arel_extensions/nodes/md5.rb +0 -0
  61. data/lib/arel_extensions/nodes/power.rb +0 -0
  62. data/lib/arel_extensions/nodes/rand.rb +0 -0
  63. data/lib/arel_extensions/nodes/repeat.rb +2 -2
  64. data/lib/arel_extensions/nodes/replace.rb +2 -2
  65. data/lib/arel_extensions/nodes/round.rb +0 -0
  66. data/lib/arel_extensions/nodes/soundex.rb +2 -2
  67. data/lib/arel_extensions/nodes/std.rb +0 -0
  68. data/lib/arel_extensions/nodes/substring.rb +1 -1
  69. data/lib/arel_extensions/nodes/sum.rb +0 -0
  70. data/lib/arel_extensions/nodes/then.rb +1 -1
  71. data/lib/arel_extensions/nodes/trim.rb +2 -2
  72. data/lib/arel_extensions/nodes/union.rb +4 -4
  73. data/lib/arel_extensions/nodes/union_all.rb +3 -3
  74. data/lib/arel_extensions/nodes/wday.rb +0 -0
  75. data/lib/arel_extensions/nodes.rb +0 -0
  76. data/lib/arel_extensions/null_functions.rb +0 -0
  77. data/lib/arel_extensions/predications.rb +10 -10
  78. data/lib/arel_extensions/railtie.rb +1 -1
  79. data/lib/arel_extensions/set_functions.rb +3 -3
  80. data/lib/arel_extensions/string_functions.rb +8 -8
  81. data/lib/arel_extensions/tasks.rb +2 -2
  82. data/lib/arel_extensions/version.rb +1 -1
  83. data/lib/arel_extensions/visitors/convert_format.rb +0 -0
  84. data/lib/arel_extensions/visitors/ibm_db.rb +20 -20
  85. data/lib/arel_extensions/visitors/mssql.rb +150 -130
  86. data/lib/arel_extensions/visitors/mysql.rb +147 -149
  87. data/lib/arel_extensions/visitors/oracle.rb +141 -135
  88. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  89. data/lib/arel_extensions/visitors/postgresql.rb +147 -139
  90. data/lib/arel_extensions/visitors/sqlite.rb +85 -87
  91. data/lib/arel_extensions/visitors/to_sql.rb +146 -148
  92. data/lib/arel_extensions/visitors.rb +7 -7
  93. data/lib/arel_extensions.rb +56 -32
  94. data/test/arelx_test_helper.rb +14 -13
  95. data/test/database.yml +5 -5
  96. data/test/real_db_test.rb +81 -81
  97. data/test/support/fake_record.rb +2 -2
  98. data/test/test_comparators.rb +5 -5
  99. data/test/visitors/test_bulk_insert_oracle.rb +5 -5
  100. data/test/visitors/test_bulk_insert_sqlite.rb +5 -5
  101. data/test/visitors/test_bulk_insert_to_sql.rb +5 -5
  102. data/test/visitors/test_oracle.rb +14 -14
  103. data/test/visitors/test_to_sql.rb +87 -87
  104. data/test/with_ar/all_agnostic_test.rb +411 -306
  105. data/test/with_ar/insert_agnostic_test.rb +19 -16
  106. data/test/with_ar/test_bulk_sqlite.rb +5 -5
  107. data/test/with_ar/test_math_sqlite.rb +12 -12
  108. data/test/with_ar/test_string_mysql.rb +20 -20
  109. data/test/with_ar/test_string_sqlite.rb +20 -20
  110. data/version_v1.rb +1 -1
  111. data/version_v2.rb +1 -1
  112. metadata +3 -9
  113. data/.travis/oracle/download.js +0 -152
  114. data/.travis/oracle/download.sh +0 -30
  115. data/.travis/oracle/download_ojdbc.js +0 -116
  116. data/.travis/oracle/install.sh +0 -34
  117. data/.travis/setup_accounts.sh +0 -9
  118. data/.travis/sqlite3/extension-functions.sh +0 -6
  119. 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
- collector = visit o.left.ai_collate, collector
37
- collector << ' LIKE '
38
- collector = visit o.right.ai_collate, collector
39
- if o.escape
40
- collector << ' ESCAPE '
41
- visit o.escape, collector
42
- else
43
- collector
44
- end
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
- collector = visit o.left.collate(true,true), collector
49
- collector << ' LIKE '
50
- collector = visit o.right.collate(true,true), collector
51
- if o.escape
52
- collector << ' ESCAPE '
53
- visit o.escape, collector
54
- else
55
- collector
56
- end
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 << "date("
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 << "julianday("
113
+ collector << 'julianday('
116
114
  collector = visit o.left, collector
117
- collector << ") - julianday("
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 << "instr("
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 << "SUBSTR("
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
- collector = visit o.expr, collector
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 << "RANDOM("
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 << " REGEXP"
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 << " NOT REGEXP "
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 << "CAST(CASE WHEN "
211
+ collector << 'CAST(CASE WHEN '
214
212
  collector = visit o.left, collector
215
- collector << " >= 0 THEN CAST("
213
+ collector << ' >= 0 THEN CAST('
216
214
  collector = visit o.left, collector
217
- collector << " AS INT) WHEN CAST("
215
+ collector << ' AS INT) WHEN CAST('
218
216
  collector = visit o.left, collector
219
- collector << " AS INT) = "
217
+ collector << ' AS INT) = '
220
218
  collector = visit o.left, collector
221
- collector << " THEN CAST("
219
+ collector << ' THEN CAST('
222
220
  collector = visit o.left, collector
223
- collector << " AS INT) ELSE CAST(("
221
+ collector << ' AS INT) ELSE CAST(('
224
222
  collector = visit o.left, collector
225
- collector << " - 1.0) AS INT) END AS FLOAT)"
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 << "CASE WHEN ROUND("
228
+ collector << 'CASE WHEN ROUND('
231
229
  collector = visit o.left, collector
232
- collector << ", 1) > ROUND("
230
+ collector << ', 1) > ROUND('
233
231
  collector = visit o.left, collector
234
- collector << ") THEN ROUND("
232
+ collector << ') THEN ROUND('
235
233
  collector = visit o.left, collector
236
- collector << ") + 1 ELSE ROUND("
234
+ collector << ') + 1 ELSE ROUND('
237
235
  collector = visit o.left, collector
238
- collector << ") END"
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
- case value
249
- when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
250
- collector = visit value.as(attr.name), collector
251
- else
252
- collector << quote(value, attr && column_for(attr)).to_s
253
- if idx == 0
254
- collector << " AS "
255
- collector << quote(attr.name)
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
- case value
271
- when Arel::Nodes::SqlLiteral, Arel::Nodes::BindParam
272
- collector = visit value.as(attr.name), collector
273
- when Integer
274
- collector << value.to_s
275
- if idx == 0
276
- collector << " AS "
277
- collector << quote(attr.name)
278
- end
279
- else
280
- collector << (attr && attr.able_to_type_cast? ? quote(attr.type_cast_for_database(value)) : quote(value).to_s)
281
- if idx == 0
282
- collector << " AS "
283
- collector << quote(attr.name)
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 << " UNION "
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 << " UNION ALL "
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
- return Arel::Nodes::NamedFunction.new('STRFTIME',[element, '%H:%M:%S'])
328
+ Arel::Nodes::NamedFunction.new('STRFTIME', [element, '%H:%M:%S'])
331
329
  elsif element.is_a?(Arel::Attributes::Attribute)
332
- col = ArelExtensions::column_of(element.relation.table_name, element.name.to_s)
330
+ col = Arel.column_of(element.relation.table_name, element.name.to_s)
333
331
  if col && (col.type == :time)
334
- return Arel::Nodes::NamedFunction.new('STRFTIME',[element, '%H:%M:%S'])
332
+ Arel::Nodes::NamedFunction.new('STRFTIME', [element, '%H:%M:%S'])
335
333
  else
336
- return element
334
+ element
337
335
  end
338
336
  else
339
- return element
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::Nodes.build_quoted(o.original_string),o.left])
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