arel_extensions 2.1.1 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -2
  3. data/.github/workflows/ruby.yml +4 -4
  4. data/.rubocop.yml +25 -1
  5. data/Gemfile +10 -10
  6. data/README.md +24 -4
  7. data/Rakefile +4 -4
  8. data/TODO +0 -1
  9. data/arel_extensions.gemspec +11 -11
  10. data/gemfiles/rails3.gemfile +10 -10
  11. data/gemfiles/rails4.gemfile +13 -13
  12. data/gemfiles/rails5_0.gemfile +12 -12
  13. data/gemfiles/rails5_1_4.gemfile +12 -12
  14. data/gemfiles/rails5_2.gemfile +13 -13
  15. data/gemfiles/rails6.gemfile +11 -11
  16. data/gemfiles/rails6_1.gemfile +11 -11
  17. data/gemfiles/rails7.gemfile +7 -7
  18. data/gemspecs/arel_extensions-v1.gemspec +12 -12
  19. data/gemspecs/arel_extensions-v2.gemspec +11 -11
  20. data/init/mssql.sql +0 -0
  21. data/init/mysql.sql +0 -0
  22. data/init/oracle.sql +0 -0
  23. data/init/postgresql.sql +0 -0
  24. data/init/sqlite.sql +0 -0
  25. data/lib/arel_extensions/attributes.rb +2 -2
  26. data/lib/arel_extensions/boolean_functions.rb +2 -4
  27. data/lib/arel_extensions/common_sql_functions.rb +10 -10
  28. data/lib/arel_extensions/comparators.rb +14 -14
  29. data/lib/arel_extensions/date_duration.rb +7 -7
  30. data/lib/arel_extensions/helpers.rb +16 -13
  31. data/lib/arel_extensions/insert_manager.rb +1 -1
  32. data/lib/arel_extensions/math.rb +16 -18
  33. data/lib/arel_extensions/math_functions.rb +18 -18
  34. data/lib/arel_extensions/nodes/abs.rb +0 -0
  35. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -0
  36. data/lib/arel_extensions/nodes/blank.rb +1 -1
  37. data/lib/arel_extensions/nodes/case.rb +4 -6
  38. data/lib/arel_extensions/nodes/cast.rb +3 -3
  39. data/lib/arel_extensions/nodes/ceil.rb +0 -0
  40. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  41. data/lib/arel_extensions/nodes/coalesce.rb +0 -0
  42. data/lib/arel_extensions/nodes/collate.rb +9 -9
  43. data/lib/arel_extensions/nodes/concat.rb +2 -2
  44. data/lib/arel_extensions/nodes/date_diff.rb +6 -6
  45. data/lib/arel_extensions/nodes/duration.rb +0 -0
  46. data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
  47. data/lib/arel_extensions/nodes/floor.rb +0 -0
  48. data/lib/arel_extensions/nodes/format.rb +1 -1
  49. data/lib/arel_extensions/nodes/formatted_number.rb +2 -2
  50. data/lib/arel_extensions/nodes/function.rb +21 -21
  51. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  52. data/lib/arel_extensions/nodes/json.rb +7 -7
  53. data/lib/arel_extensions/nodes/length.rb +0 -0
  54. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  55. data/lib/arel_extensions/nodes/locate.rb +0 -0
  56. data/lib/arel_extensions/nodes/log10.rb +0 -0
  57. data/lib/arel_extensions/nodes/matches.rb +1 -1
  58. data/lib/arel_extensions/nodes/md5.rb +0 -0
  59. data/lib/arel_extensions/nodes/power.rb +0 -0
  60. data/lib/arel_extensions/nodes/rand.rb +0 -0
  61. data/lib/arel_extensions/nodes/repeat.rb +0 -0
  62. data/lib/arel_extensions/nodes/replace.rb +2 -2
  63. data/lib/arel_extensions/nodes/round.rb +0 -0
  64. data/lib/arel_extensions/nodes/soundex.rb +2 -2
  65. data/lib/arel_extensions/nodes/std.rb +0 -0
  66. data/lib/arel_extensions/nodes/substring.rb +0 -0
  67. data/lib/arel_extensions/nodes/sum.rb +0 -0
  68. data/lib/arel_extensions/nodes/then.rb +0 -0
  69. data/lib/arel_extensions/nodes/trim.rb +0 -0
  70. data/lib/arel_extensions/nodes/union.rb +4 -4
  71. data/lib/arel_extensions/nodes/union_all.rb +3 -3
  72. data/lib/arel_extensions/nodes/wday.rb +0 -0
  73. data/lib/arel_extensions/nodes.rb +0 -0
  74. data/lib/arel_extensions/null_functions.rb +0 -0
  75. data/lib/arel_extensions/predications.rb +10 -10
  76. data/lib/arel_extensions/railtie.rb +1 -1
  77. data/lib/arel_extensions/set_functions.rb +3 -3
  78. data/lib/arel_extensions/string_functions.rb +8 -8
  79. data/lib/arel_extensions/tasks.rb +2 -2
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/convert_format.rb +0 -0
  82. data/lib/arel_extensions/visitors/ibm_db.rb +19 -19
  83. data/lib/arel_extensions/visitors/mssql.rb +139 -118
  84. data/lib/arel_extensions/visitors/mysql.rb +145 -144
  85. data/lib/arel_extensions/visitors/oracle.rb +136 -128
  86. data/lib/arel_extensions/visitors/oracle12.rb +16 -16
  87. data/lib/arel_extensions/visitors/postgresql.rb +147 -136
  88. data/lib/arel_extensions/visitors/sqlite.rb +83 -85
  89. data/lib/arel_extensions/visitors/to_sql.rb +143 -148
  90. data/lib/arel_extensions/visitors.rb +7 -7
  91. data/lib/arel_extensions.rb +46 -32
  92. data/test/arelx_test_helper.rb +14 -14
  93. data/test/database.yml +5 -5
  94. data/test/real_db_test.rb +78 -78
  95. data/test/support/fake_record.rb +1 -1
  96. data/test/test_comparators.rb +5 -5
  97. data/test/visitors/test_bulk_insert_oracle.rb +4 -4
  98. data/test/visitors/test_bulk_insert_sqlite.rb +4 -4
  99. data/test/visitors/test_bulk_insert_to_sql.rb +4 -4
  100. data/test/visitors/test_oracle.rb +14 -14
  101. data/test/visitors/test_to_sql.rb +82 -82
  102. data/test/with_ar/all_agnostic_test.rb +415 -313
  103. data/test/with_ar/insert_agnostic_test.rb +17 -14
  104. data/test/with_ar/test_bulk_sqlite.rb +4 -4
  105. data/test/with_ar/test_math_sqlite.rb +12 -12
  106. data/test/with_ar/test_string_mysql.rb +20 -20
  107. data/test/with_ar/test_string_sqlite.rb +20 -20
  108. data/version_v1.rb +1 -1
  109. data/version_v2.rb +1 -1
  110. metadata +2 -9
  111. data/.travis/oracle/download.js +0 -152
  112. data/.travis/oracle/download.sh +0 -30
  113. data/.travis/oracle/download_ojdbc.js +0 -116
  114. data/.travis/oracle/install.sh +0 -34
  115. data/.travis/setup_accounts.sh +0 -9
  116. data/.travis/sqlite3/extension-functions.sh +0 -6
  117. data/.travis.yml +0 -193
@@ -8,7 +8,8 @@ module ArelExtensions
8
8
 
9
9
  DATE_FORMAT_DIRECTIVES = { # ISO C / POSIX
10
10
  '%Y' => '%Y', '%C' => '', '%y' => '%y', '%m' => '%m', '%B' => '%M', '%b' => '%b', '%^b' => '%b', # year, month
11
- '%d' => '%d', '%e' => '%e', '%j' => '%j', '%w' => '%w', '%A' => '%W', # day, weekday
11
+ '%V' => '%v', '%G' => '%x', # ISO week number and year of week
12
+ '%d' => '%d', '%e' => '%e', '%j' => '%j', '%w' => '%w', '%a' => '%a', '%A' => '%W', # day, weekday
12
13
  '%H' => '%H', '%k' => '%k', '%I' => '%I', '%l' => '%l', '%P' => '%p', '%p' => '%p', # hours
13
14
  '%M' => '%i', '%S' => '%S', '%L' => '', '%N' => '%f', '%z' => ''
14
15
  }.freeze
@@ -16,22 +17,22 @@ module ArelExtensions
16
17
 
17
18
  # Math functions
18
19
  def visit_ArelExtensions_Nodes_Log10 o, collector
19
- collector << "LOG10("
20
- o.expressions.each_with_index { |arg, i|
21
- collector << Arel::Visitors::ToSql::COMMA if i != 0
22
- collector = visit arg, collector
23
- }
24
- collector << ")"
25
- collector
20
+ collector << 'LOG10('
21
+ o.expressions.each_with_index { |arg, i|
22
+ collector << Arel::Visitors::ToSql::COMMA if i != 0
23
+ collector = visit arg, collector
24
+ }
25
+ collector << ')'
26
+ collector
26
27
  end
27
28
 
28
29
  def visit_ArelExtensions_Nodes_Power o, collector
29
- collector << "POW("
30
+ collector << 'POW('
30
31
  o.expressions.each_with_index { |arg, i|
31
32
  collector << Arel::Visitors::ToSql::COMMA if i != 0
32
33
  collector = visit arg, collector
33
34
  }
34
- collector << ")"
35
+ collector << ')'
35
36
  collector
36
37
  end
37
38
 
@@ -44,10 +45,9 @@ module ArelExtensions
44
45
  collector << ')'
45
46
  if o.escape
46
47
  collector << ' ESCAPE '
47
- visit o.escape, collector
48
- else
49
- collector
48
+ collector = visit o.escape, collector
50
49
  end
50
+ collector
51
51
  end
52
52
 
53
53
  def visit_ArelExtensions_Nodes_AiMatches o, collector
@@ -56,10 +56,9 @@ module ArelExtensions
56
56
  collector = visit o.right.ai_collate, collector
57
57
  if o.escape
58
58
  collector << ' ESCAPE '
59
- visit o.escape, collector
60
- else
61
- collector
59
+ collector = visit o.escape, collector
62
60
  end
61
+ collector
63
62
  end
64
63
 
65
64
  def visit_ArelExtensions_Nodes_AiIMatches o, collector
@@ -68,22 +67,20 @@ module ArelExtensions
68
67
  collector = visit o.right.ai_collate, collector
69
68
  if o.escape
70
69
  collector << ' ESCAPE '
71
- visit o.escape, collector
72
- else
73
- collector
70
+ collector = visit o.escape, collector
74
71
  end
72
+ collector
75
73
  end
76
74
 
77
75
  def visit_ArelExtensions_Nodes_SMatches o, collector
78
- collector = visit o.left.collate, collector
79
- collector << ' LIKE '
80
- collector = visit o.right.collate, collector
81
- if o.escape
82
- collector << ' ESCAPE '
83
- visit o.escape, collector
84
- else
85
- collector
86
- end
76
+ collector = visit o.left.collate, collector
77
+ collector << ' LIKE '
78
+ collector = visit o.right.collate, collector
79
+ if o.escape
80
+ collector << ' ESCAPE '
81
+ collector = visit o.escape, collector
82
+ end
83
+ collector
87
84
  end
88
85
 
89
86
  def visit_ArelExtensions_Nodes_IDoesNotMatch o, collector
@@ -94,10 +91,9 @@ module ArelExtensions
94
91
  collector << ')'
95
92
  if o.escape
96
93
  collector << ' ESCAPE '
97
- visit o.escape, collector
98
- else
99
- collector
94
+ collector = visit o.escape, collector
100
95
  end
96
+ collector
101
97
  end
102
98
 
103
99
  def visit_ArelExtensions_Nodes_Collate o, collector
@@ -105,7 +101,7 @@ module ArelExtensions
105
101
  case o.expressions.first
106
102
  when Arel::Attributes::Attribute
107
103
  case o.option
108
- when 'latin1','utf8'
104
+ when 'latin1', 'utf8'
109
105
  o.option
110
106
  else
111
107
  Arel::Table.engine.connection.charset || 'utf8'
@@ -127,27 +123,27 @@ module ArelExtensions
127
123
  end
128
124
 
129
125
  def visit_ArelExtensions_Nodes_Concat o, collector
130
- collector << "CONCAT("
126
+ collector << 'CONCAT('
131
127
  o.expressions.each_with_index { |arg, i|
132
128
  collector << COMMA if i != 0
133
129
  if (arg.is_a?(Numeric)) || (arg.is_a?(Arel::Attributes::Attribute))
134
- collector << "CAST("
130
+ collector << 'CAST('
135
131
  collector = visit arg, collector
136
- collector << " AS char)"
132
+ collector << ' AS char)'
137
133
  else
138
134
  collector = visit arg, collector
139
135
  end
140
136
  }
141
- collector << ")"
137
+ collector << ')'
142
138
  collector
143
139
  end
144
140
 
145
141
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
146
- collector << "GROUP_CONCAT("
142
+ collector << 'GROUP_CONCAT('
147
143
  collector = visit o.left, collector
148
144
  if !o.order.blank?
149
145
  collector << ' ORDER BY '
150
- o.order.each_with_index do |order,i|
146
+ o.order.each_with_index do |order, i|
151
147
  collector << Arel::Visitors::ToSql::COMMA if i != 0
152
148
  collector = visit order, collector
153
149
  end
@@ -156,77 +152,85 @@ module ArelExtensions
156
152
  collector << ' SEPARATOR '
157
153
  collector = visit o.separator, collector
158
154
  end
159
- collector << ")"
155
+ collector << ')'
160
156
  collector
161
157
  end
162
158
 
163
159
  def visit_ArelExtensions_Nodes_Trim o, collector
164
- collector << 'TRIM(' # BOTH
165
- collector = visit o.right, collector
166
- collector << " FROM "
167
- collector = visit o.left, collector
168
- collector << ")"
169
- collector
160
+ collector << 'TRIM(' # BOTH
161
+ collector = visit o.right, collector
162
+ collector << ' FROM '
163
+ collector = visit o.left, collector
164
+ collector << ')'
165
+ collector
170
166
  end
171
167
 
172
168
  def visit_ArelExtensions_Nodes_Ltrim o, collector
173
- collector << 'TRIM(LEADING '
174
- collector = visit o.right, collector
175
- collector << " FROM "
176
- collector = visit o.left, collector
177
- collector << ")"
178
- collector
169
+ collector << 'TRIM(LEADING '
170
+ collector = visit o.right, collector
171
+ collector << ' FROM '
172
+ collector = visit o.left, collector
173
+ collector << ')'
174
+ collector
179
175
  end
180
176
 
181
177
  def visit_ArelExtensions_Nodes_Rtrim o, collector
182
178
  collector << 'TRIM(TRAILING '
183
179
  collector = visit o.right, collector
184
- collector << " FROM "
180
+ collector << ' FROM '
185
181
  collector = visit o.left, collector
186
- collector << ")"
182
+ collector << ')'
187
183
  collector
188
184
  end
189
185
 
190
186
  def visit_ArelExtensions_Nodes_Repeat o, collector
191
- collector << "REPEAT("
187
+ collector << 'REPEAT('
192
188
  o.expressions.each_with_index { |arg, i|
193
189
  collector << Arel::Visitors::ToSql::COMMA if i != 0
194
190
  collector = visit arg, collector
195
191
  }
196
- collector << ")"
192
+ collector << ')'
197
193
  collector
198
194
  end
199
195
 
200
196
  def visit_ArelExtensions_Nodes_RegexpReplace o, collector
201
197
  if !regexp_replace_supported?
202
- warn("Warning : ArelExtensions: REGEXP_REPLACE does not seem to be available in the current version of the DBMS, it might crash")
198
+ warn('Warning: ArelExtensions: REGEXP_REPLACE does not seem to be available in the current version of the DBMS, it might crash')
203
199
  end
204
- super(o,collector)
200
+ super(o, collector)
205
201
  end
206
202
 
207
203
  def visit_ArelExtensions_Nodes_Format o, collector
208
204
  case o.col_type
209
205
  when :date, :datetime, :time
210
206
  fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
211
- collector << "DATE_FORMAT("
212
- collector << "CONVERT_TZ(" if o.time_zone
207
+ collector << 'DATE_FORMAT('
208
+ collector << 'CONVERT_TZ(' if o.time_zone
213
209
  collector = visit o.left, collector
214
- if o.time_zone
210
+ case o.time_zone
211
+ when Hash
212
+ src_tz, dst_tz = o.time_zone.first
213
+ collector << COMMA
214
+ collector = visit Arel.quoted(src_tz), collector
215
+ collector << COMMA
216
+ collector = visit Arel.quoted(dst_tz), collector
217
+ collector << ')'
218
+ when String
215
219
  collector << COMMA << "'UTC'" << COMMA
216
- collector = visit o.time_zone, collector
220
+ collector = visit Arel.quoted(o.time_zone), collector
217
221
  collector << ')'
218
222
  end
219
223
  collector << COMMA
220
- collector = visit Arel::Nodes.build_quoted(fmt), collector
221
- collector << ")"
224
+ collector = visit Arel.quoted(fmt), collector
225
+ collector << ')'
222
226
  when :integer, :float, :decimal
223
- collector << "FORMAT("
227
+ collector << 'FORMAT('
224
228
  collector = visit o.left, collector
225
229
  collector << Arel::Visitors::ToSql::COMMA
226
230
  collector << '2'
227
231
  collector << Arel::Visitors::ToSql::COMMA
228
232
  collector = visit o.right, collector
229
- collector << ")"
233
+ collector << ')'
230
234
  else
231
235
  collector = visit o.left, collector
232
236
  end
@@ -244,7 +248,7 @@ module ArelExtensions
244
248
  collector = visit o.right, collector
245
249
  collector << COMMA
246
250
  collector = visit o.left, collector
247
- collector << ")"
251
+ collector << ')'
248
252
  else
249
253
  collector << '('
250
254
  collector = visit o.left, collector
@@ -264,81 +268,79 @@ module ArelExtensions
264
268
  end
265
269
 
266
270
  def visit_ArelExtensions_Nodes_DateAdd o, collector
267
- collector << "DATE_ADD("
271
+ collector << 'DATE_ADD('
268
272
  collector = visit o.left, collector
269
273
  collector << COMMA
270
274
  collector = visit o.mysql_value(o.right), collector
271
- collector << ")"
275
+ collector << ')'
272
276
  collector
273
277
  end
274
278
 
275
279
  def visit_ArelExtensions_Nodes_Duration o, collector
276
280
  if o.left == 'wd'
277
- collector << "(WEEKDAY("
281
+ collector << '(WEEKDAY('
278
282
  collector = visit o.right, collector
279
- collector << ") + 1) % 7"
283
+ collector << ') + 1) % 7'
280
284
  else
281
285
  if o.with_interval
282
- case o.left
283
- when 'd','m','y'
284
- interval = 'DAY'
285
- when 'h','mn','s'
286
- interval = 'SECOND'
287
- when /i\z/
288
- interval = DATE_MAPPING[o.left[0..-2]]
289
- else
290
- interval = nil
291
- end
286
+ interval =
287
+ case o.left
288
+ when 'd', 'm', 'y'
289
+ 'DAY'
290
+ when 'h', 'mn', 's'
291
+ 'SECOND'
292
+ when /i\z/
293
+ DATE_MAPPING[o.left[0..-2]]
294
+ end
292
295
  end
293
- collector << " INTERVAL " if o.with_interval && interval
296
+ collector << ' INTERVAL ' if o.with_interval && interval
294
297
  collector << "#{DATE_MAPPING[o.left]}("
295
298
  collector = visit o.right, collector
296
- collector << ")"
299
+ collector << ')'
297
300
  collector << " #{interval} " if o.with_interval && interval
298
301
  end
299
302
  collector
300
303
  end
301
304
 
302
305
  def visit_ArelExtensions_Nodes_IsNull o, collector
303
- collector << "ISNULL("
306
+ collector << 'ISNULL('
304
307
  collector = visit o.expr, collector
305
- collector << ")"
308
+ collector << ')'
306
309
  collector
307
310
  end
308
311
 
309
312
  def visit_ArelExtensions_Nodes_IsNotNull o, collector
310
- collector << "NOT ISNULL("
313
+ collector << 'NOT ISNULL('
311
314
  collector = visit o.expr, collector
312
- collector << ")"
315
+ collector << ')'
313
316
  collector
314
317
  end
315
318
 
316
319
  def visit_ArelExtensions_Nodes_Wday o, collector
317
- collector << "(WEEKDAY("
320
+ collector << '(WEEKDAY('
318
321
  collector = visit o.date, collector
319
- collector << ") + 1) % 7"
322
+ collector << ') + 1) % 7'
320
323
  collector
321
324
  end
322
325
 
323
326
  def visit_ArelExtensions_Nodes_Cast o, collector
324
- collector << "CAST("
325
- collector = visit o.left, collector
326
- collector << " AS "
327
327
  as_attr =
328
- Arel::Nodes::SqlLiteral.new(
329
- case o.as_attr
330
- when :string then 'char'
331
- when :time then 'time'
332
- when :int then 'signed'
333
- when :number, :decimal then 'decimal(20,6)'
334
- when :datetime then 'datetime'
335
- when :date then 'date'
336
- when :binary then 'binary'
337
- else o.as_attr.to_s
338
- end
339
- )
340
- collector = visit as_attr, collector
341
- collector << ")"
328
+ case o.as_attr
329
+ when :binary then 'binary'
330
+ when :date then 'date'
331
+ when :datetime then 'datetime'
332
+ when :int then 'signed'
333
+ when :number, :decimal then 'decimal(20,6)'
334
+ when :string then 'char'
335
+ when :time then 'time'
336
+ else o.as_attr.to_s
337
+ end
338
+
339
+ collector << 'CAST('
340
+ collector = visit o.left, collector
341
+ collector << ' AS '
342
+ collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector
343
+ collector << ')'
342
344
  collector
343
345
  end
344
346
 
@@ -348,7 +350,7 @@ module ArelExtensions
348
350
  o = o.dup
349
351
  o.orders = []
350
352
  end
351
- old_visit_Arel_Nodes_SelectStatement(o,collector)
353
+ old_visit_Arel_Nodes_SelectStatement(o, collector)
352
354
  end
353
355
 
354
356
  alias_method(:old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As) rescue nil
@@ -360,7 +362,7 @@ module ArelExtensions
360
362
  else
361
363
  collector = visit o.left, collector
362
364
  end
363
- collector << " AS "
365
+ collector << ' AS '
364
366
 
365
367
  # sometimes these values are already quoted, if they are, don't double quote it
366
368
  quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '`' && o.right[-1] != '`'
@@ -370,13 +372,12 @@ module ArelExtensions
370
372
  collector << '`' if quote
371
373
 
372
374
  collector
373
- collector
374
375
  end
375
376
 
376
377
  def visit_ArelExtensions_Nodes_FormattedNumber o, collector
377
378
  col = o.left.coalesce(0)
378
- params = o.locale ? [o.precision,Arel::Nodes.build_quoted(o.locale)] : [o.precision]
379
- sign = ArelExtensions::Nodes::Case.new.when(col<0).
379
+ params = o.locale ? [o.precision, Arel.quoted(o.locale)] : [o.precision]
380
+ sign = Arel.when(col < 0).
380
381
  then('-').
381
382
  else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
382
383
  sign_length = ArelExtensions::Nodes::Length.new([sign])
@@ -384,28 +385,28 @@ module ArelExtensions
384
385
  number =
385
386
  if o.scientific_notation
386
387
  ArelExtensions::Nodes::Concat.new([
387
- Arel::Nodes::NamedFunction.new('FORMAT',[
388
- col.abs/Arel::Nodes.build_quoted(10).pow(col.abs.log10.floor)
389
- ]+params),
388
+ Arel::Nodes::NamedFunction.new('FORMAT', [
389
+ col.abs / Arel.quoted(10).pow(col.abs.log10.floor)
390
+ ] + params),
390
391
  o.type,
391
- Arel::Nodes::NamedFunction.new('FORMAT',[
392
+ Arel::Nodes::NamedFunction.new('FORMAT', [
392
393
  col.abs.log10.floor,
393
394
  0
394
395
  ])
395
396
  ])
396
397
  else
397
- Arel::Nodes::NamedFunction.new('FORMAT',[col.abs]+params)
398
+ Arel::Nodes::NamedFunction.new('FORMAT', [col.abs] + params)
398
399
  end
399
400
 
400
- repeated_char = (o.width == 0) ? Arel::Nodes.build_quoted('') : ArelExtensions::Nodes::Case.new().
401
- when(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length)>0).
402
- then(Arel::Nodes.build_quoted(
401
+ repeated_char = (o.width == 0) ? Arel.quoted('') : ArelExtensions::Nodes::Case.new.
402
+ when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0).
403
+ then(Arel.quoted(
403
404
  o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
404
- ).repeat(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length))
405
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
405
406
  ).
406
407
  else('')
407
- before = (!o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
408
- middle = (o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
408
+ before = (!o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
409
+ middle = (o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
409
410
  after = o.flags.include?('-') ? repeated_char : ''
410
411
  full_number = ArelExtensions::Nodes::Concat.new([
411
412
  before,
@@ -414,45 +415,45 @@ module ArelExtensions
414
415
  number,
415
416
  after
416
417
  ])
417
- collector = visit ArelExtensions::Nodes::Concat.new([Arel::Nodes.build_quoted(o.prefix),full_number,Arel::Nodes.build_quoted(o.suffix)]), collector
418
+ collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
418
419
  collector
419
420
  end
420
421
 
421
422
  def visit_Aggregate_For_AggregateFunction o, collector
422
423
  if !window_supported?
423
- warn("Warning : ArelExtensions: Window Functions are not available in the current version of the DBMS.")
424
- return collector
424
+ warn('Warning: ArelExtensions: Window Functions are not available in the current version of the DBMS.')
425
+ return collector
425
426
  end
426
427
 
427
428
  if !o.order.empty? || !o.group.empty?
428
- collector << " OVER ("
429
+ collector << ' OVER ('
429
430
  if !o.group.empty?
430
- collector << " PARTITION BY ("
431
+ collector << ' PARTITION BY ('
431
432
  visit o.group, collector
432
- collector << ")"
433
+ collector << ')'
433
434
  end
434
435
  if !o.order.empty?
435
- collector << " ORDER BY ("
436
+ collector << ' ORDER BY ('
436
437
  visit o.order, collector
437
- collector << ")"
438
+ collector << ')'
438
439
  end
439
- collector << ")"
440
+ collector << ')'
440
441
  end
441
442
  collector
442
443
  end
443
444
 
444
445
  def visit_ArelExtensions_Nodes_Std o, collector
445
- collector << (o.unbiased_estimator ? "STDDEV_SAMP(" : "STDDEV_POP(")
446
+ collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(')
446
447
  visit o.left, collector
447
- collector << ")"
448
+ collector << ')'
448
449
  visit_Aggregate_For_AggregateFunction o, collector
449
450
  collector
450
451
  end
451
452
 
452
453
  def visit_ArelExtensions_Nodes_Variance o, collector
453
- collector << (o.unbiased_estimator ? "VAR_SAMP(" : "VAR_POP(")
454
+ collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(')
454
455
  visit o.left, collector
455
- collector << ")"
456
+ collector << ')'
456
457
  visit_Aggregate_For_AggregateFunction o, collector
457
458
  collector
458
459
  end
@@ -484,13 +485,13 @@ module ArelExtensions
484
485
  # corresponding mysql version of the current mariadb version (which is not very helpful most of the time)
485
486
  end
486
487
 
487
- def visit_ArelExtensions_Nodes_Json o,collector
488
+ def visit_ArelExtensions_Nodes_Json o, collector
488
489
  return super if !json_supported?
489
490
 
490
491
  case o.dict
491
492
  when Array
492
493
  collector << 'JSON_ARRAY('
493
- o.dict.each.with_index do |v,i|
494
+ o.dict.each.with_index do |v, i|
494
495
  if i != 0
495
496
  collector << COMMA
496
497
  end
@@ -499,7 +500,7 @@ module ArelExtensions
499
500
  collector << ')'
500
501
  when Hash
501
502
  collector << 'JSON_OBJECT('
502
- o.dict.each.with_index do |(k,v),i|
503
+ o.dict.each.with_index do |(k, v), i|
503
504
  if i != 0
504
505
  collector << COMMA
505
506
  end
@@ -514,9 +515,9 @@ module ArelExtensions
514
515
  collector
515
516
  end
516
517
 
517
- def visit_ArelExtensions_Nodes_JsonMerge o,collector
518
+ def visit_ArelExtensions_Nodes_JsonMerge o, collector
518
519
  collector << 'JSON_MERGE_PATCH('
519
- o.expressions.each.with_index do |v,i|
520
+ o.expressions.each.with_index do |v, i|
520
521
  if i != 0
521
522
  collector << COMMA
522
523
  end
@@ -526,27 +527,27 @@ module ArelExtensions
526
527
  collector
527
528
  end
528
529
 
529
- def visit_ArelExtensions_Nodes_JsonGet o,collector
530
+ def visit_ArelExtensions_Nodes_JsonGet o, collector
530
531
  collector << 'JSON_EXTRACT('
531
532
  collector = visit o.dict, collector
532
533
  collector << COMMA
533
534
  if o.key.is_a?(Integer)
534
535
  collector << "\"$[#{o.key}]\""
535
536
  else
536
- collector = visit Arel::Nodes.build_quoted('$.')+o.key, collector
537
+ collector = visit Arel.quoted('$.') + o.key, collector
537
538
  end
538
539
  collector << ')'
539
540
  collector
540
541
  end
541
542
 
542
- def visit_ArelExtensions_Nodes_JsonSet o,collector
543
+ def visit_ArelExtensions_Nodes_JsonSet o, collector
543
544
  collector << 'JSON_SET('
544
545
  collector = visit o.dict, collector
545
546
  collector << COMMA
546
547
  if o.key.is_a?(Integer)
547
548
  collector << "\"$[#{o.key}]\""
548
549
  else
549
- collector = visit Arel::Nodes.build_quoted('$.')+o.key, collector
550
+ collector = visit Arel.quoted('$.') + o.key, collector
550
551
  end
551
552
  collector << COMMA
552
553
  collector = visit o.value, collector
@@ -565,7 +566,7 @@ module ArelExtensions
565
566
  case o.dict
566
567
  when Hash
567
568
  collector << 'JSON_MERGE_PATCH(' if o.dict.length > 1
568
- o.dict.each.with_index do |(k,v),i|
569
+ o.dict.each.with_index do |(k, v), i|
569
570
  if i != 0
570
571
  collector << COMMA
571
572
  end