arel_extensions 1.3.1 → 1.3.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 +12 -12
  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,10 +8,11 @@ module ArelExtensions
8
8
 
9
9
  DATE_FORMAT_DIRECTIVES = {
10
10
  '%Y' => 'YYYY', '%C' => 'CC', '%y' => 'YY',
11
- '%m' => 'MM', '%B' => 'Month', '%^B' => 'MONTH', '%b' => 'Mon', '%^b' => 'MON',
12
- '%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%A' => 'Day', # day, weekday
13
- '%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
14
- '%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz', # seconds, subseconds
11
+ '%m' => 'MM', '%B' => 'TMMonth', '%^B' => 'TMMONTH', '%b' => 'TMMon', '%^b' => 'TMMON',
12
+ '%V' => 'IW', '%G' => 'IYYY', # ISO week number and year of week
13
+ '%d' => 'DD', '%e' => 'FMDD', '%j' => 'DDD', '%w' => '', '%a' => 'TMDy', '%A' => 'TMDay', # day, weekday
14
+ '%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
15
+ '%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz', # seconds, subseconds
15
16
  '%%' => '%',
16
17
  }.freeze
17
18
 
@@ -20,33 +21,33 @@ module ArelExtensions
20
21
  }.freeze
21
22
 
22
23
  def visit_ArelExtensions_Nodes_Rand o, collector
23
- collector << "RANDOM("
24
+ collector << 'RANDOM('
24
25
  if (o.left != nil && o.right != nil)
25
26
  collector = visit o.left, collector
26
27
  collector << COMMA
27
28
  collector = isit o.right, collector
28
29
  end
29
- collector << ")"
30
+ collector << ')'
30
31
  collector
31
32
  end
32
33
 
33
34
  def visit_ArelExtensions_Nodes_Power o, collector
34
- collector << "POWER("
35
+ collector << 'POWER('
35
36
  o.expressions.each_with_index { |arg, i|
36
37
  collector << Arel::Visitors::ToSql::COMMA if i != 0
37
38
  collector = visit arg, collector
38
39
  }
39
- collector << ")"
40
+ collector << ')'
40
41
  collector
41
42
  end
42
43
 
43
44
  def visit_ArelExtensions_Nodes_Log10 o, collector
44
- collector << "LOG("
45
+ collector << 'LOG('
45
46
  o.expressions.each_with_index { |arg, i|
46
47
  collector << Arel::Visitors::ToSql::COMMA if i != 0
47
48
  collector = visit arg, collector
48
49
  }
49
- collector << ")"
50
+ collector << ')'
50
51
  collector
51
52
  end
52
53
 
@@ -54,7 +55,7 @@ module ArelExtensions
54
55
  remove_method(:visit_Arel_Nodes_Regexp) rescue nil
55
56
  def visit_Arel_Nodes_Regexp o, collector
56
57
  collector = visit o.left, collector
57
- collector << " ~ "
58
+ collector << ' ~ '
58
59
  collector = visit o.right, collector
59
60
  collector
60
61
  end
@@ -62,7 +63,7 @@ module ArelExtensions
62
63
  remove_method(:visit_Arel_Nodes_NotRegexp) rescue nil
63
64
  def visit_Arel_Nodes_NotRegexp o, collector
64
65
  collector = visit o.left, collector
65
- collector << " !~ "
66
+ collector << ' !~ '
66
67
  collector = visit o.right, collector
67
68
  collector
68
69
  end
@@ -73,7 +74,7 @@ module ArelExtensions
73
74
  collector = visit arg, collector
74
75
  collector << ' || ' unless i == o.expressions.length - 1
75
76
  }
76
- collector << ")"
77
+ collector << ')'
77
78
  collector
78
79
  end
79
80
 
@@ -86,7 +87,7 @@ module ArelExtensions
86
87
  else
87
88
  collector = visit o.left, collector
88
89
  end
89
- collector << " AS "
90
+ collector << ' AS '
90
91
 
91
92
  # sometimes these values are already quoted, if they are, don't double quote it
92
93
  quote = o.right.is_a?(Arel::Nodes::SqlLiteral) && o.right[0] != '"' && o.right[-1] != '"'
@@ -100,38 +101,38 @@ module ArelExtensions
100
101
 
101
102
  def visit_Aggregate_For_AggregateFunction o, collector
102
103
  if !o.order.blank? || !o.group.blank?
103
- collector << " OVER ("
104
+ collector << ' OVER ('
104
105
  if !o.group.blank?
105
- collector << " PARTITION BY "
106
+ collector << ' PARTITION BY '
106
107
  o.group.each_with_index do |group, i|
107
108
  collector << COMMA if i != 0
108
109
  visit group, collector
109
110
  end
110
111
  end
111
112
  if !o.order.blank?
112
- collector << " ORDER BY "
113
+ collector << ' ORDER BY '
113
114
  o.order.each_with_index do |order, i|
114
115
  collector << COMMA if i != 0
115
116
  visit order, collector
116
117
  end
117
118
  end
118
- collector << ")"
119
+ collector << ')'
119
120
  end
120
121
  collector
121
122
  end
122
123
 
123
124
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
124
- collector << "array_to_string(array_agg("
125
+ collector << 'array_to_string(array_agg('
125
126
  collector = visit o.left, collector
126
127
  if o.order && !o.order.blank?
127
- collector << " ORDER BY"
128
+ collector << ' ORDER BY'
128
129
  o.order.each_with_index do |order, i|
129
130
  collector << COMMA if i != 0
130
- collector << " "
131
+ collector << ' '
131
132
  visit order, collector
132
133
  end
133
134
  end
134
- collector << ")"
135
+ collector << ')'
135
136
  o.order = nil
136
137
  visit_Aggregate_For_AggregateFunction o, collector
137
138
  collector << COMMA
@@ -139,60 +140,68 @@ module ArelExtensions
139
140
  if o.separator && o.separator != 'NULL'
140
141
  visit o.separator, collector
141
142
  else
142
- visit Arel::Nodes.build_quoted(','), collector
143
+ visit Arel.quoted(','), collector
143
144
  end
144
- collector << ")"
145
+ collector << ')'
145
146
  collector
146
147
  end
147
148
 
148
149
  def visit_ArelExtensions_Nodes_Trim o, collector
149
- collector << 'TRIM(BOTH '
150
- collector = visit o.right, collector
151
- collector << " FROM "
152
- collector = visit o.left, collector
153
- collector << ")"
154
- collector
150
+ collector << 'TRIM(BOTH '
151
+ collector = visit o.right, collector
152
+ collector << ' FROM '
153
+ collector = visit o.left, collector
154
+ collector << ')'
155
+ collector
155
156
  end
156
157
 
157
158
  def visit_ArelExtensions_Nodes_Ltrim o, collector
158
- collector << 'TRIM(LEADING '
159
- collector = visit o.right, collector
160
- collector << " FROM "
161
- collector = visit o.left, collector
162
- collector << ")"
163
- collector
159
+ collector << 'TRIM(LEADING '
160
+ collector = visit o.right, collector
161
+ collector << ' FROM '
162
+ collector = visit o.left, collector
163
+ collector << ')'
164
+ collector
164
165
  end
165
166
 
166
167
  def visit_ArelExtensions_Nodes_Rtrim o, collector
167
168
  collector << 'TRIM(TRAILING '
168
169
  collector = visit o.right, collector
169
- collector << " FROM "
170
+ collector << ' FROM '
170
171
  collector = visit o.left, collector
171
- collector << ")"
172
+ collector << ')'
172
173
  collector
173
174
  end
174
175
 
175
176
  def visit_ArelExtensions_Nodes_Format o, collector
176
177
  fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
177
- collector << "TO_CHAR("
178
+ collector << 'TO_CHAR('
179
+ collector << '(' if o.time_zone
178
180
  collector = visit o.left, collector
179
- if o.time_zone
180
- collector << " AT TIME ZONE "
181
- collector = visit o.time_zone, collector
181
+ case o.time_zone
182
+ when Hash
183
+ src_tz, dst_tz = o.time_zone.first
184
+ collector << ') AT TIME ZONE '
185
+ collector = visit Arel.quoted(src_tz), collector
186
+ collector << ' AT TIME ZONE '
187
+ collector = visit Arel.quoted(dst_tz), collector
188
+ when String
189
+ collector << ') AT TIME ZONE '
190
+ collector = visit Arel.quoted(o.time_zone), collector
182
191
  end
183
192
  collector << COMMA
184
- collector = visit Arel::Nodes.build_quoted(fmt), collector
185
- collector << ")"
193
+ collector = visit Arel.quoted(fmt), collector
194
+ collector << ')'
186
195
  collector
187
196
  end
188
197
 
189
198
  def visit_ArelExtensions_Nodes_Repeat o, collector
190
- collector << "REPEAT("
199
+ collector << 'REPEAT('
191
200
  o.expressions.each_with_index { |arg, i|
192
201
  collector << Arel::Visitors::ToSql::COMMA if i != 0
193
202
  collector = visit arg, collector
194
203
  }
195
- collector << ")"
204
+ collector << ')'
196
205
  collector
197
206
  end
198
207
 
@@ -234,9 +243,9 @@ module ArelExtensions
234
243
 
235
244
  def visit_ArelExtensions_Nodes_Collate o, collector
236
245
  if o.ai
237
- collector << "unaccent("
246
+ collector << 'unaccent('
238
247
  collector = visit o.expressions.first, collector
239
- collector << ")"
248
+ collector << ')'
240
249
  elsif o.ci
241
250
  collector = visit o.expressions.first, collector
242
251
  else
@@ -255,16 +264,16 @@ module ArelExtensions
255
264
  def visit_ArelExtensions_Nodes_DateDiff o, collector
256
265
  if o.right_node_type == :ruby_date || o.right_node_type == :ruby_time || o.right_node_type == :date || o.right_node_type == :datetime || o.right_node_type == :time
257
266
  collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
258
- "DATEDIFF('second', "
267
+ "DATEDIFF('second', "
259
268
  else
260
- "DATEDIFF('day', "
269
+ "DATEDIFF('day', "
261
270
  end
262
271
  collector = visit o.right, collector
263
272
  collector << (o.right_node_type == :date ? '::date' : '::timestamp')
264
273
  collector << COMMA
265
274
  collector = visit o.left, collector
266
275
  collector << (o.left_node_type == :date ? '::date' : '::timestamp')
267
- collector << ")"
276
+ collector << ')'
268
277
  else
269
278
  collector << '('
270
279
  collector = visit o.left, collector
@@ -281,57 +290,57 @@ module ArelExtensions
281
290
  def visit_ArelExtensions_Nodes_Duration o, collector
282
291
  if o.with_interval
283
292
  interval = case o.left
284
- when 'd','m','y'
293
+ when 'd', 'm', 'y'
285
294
  'DAY'
286
- when 'h','mn','s'
295
+ when 'h', 'mn', 's'
287
296
  'SECOND'
288
297
  when /i\z/
289
- collector << "("
298
+ collector << '('
290
299
  collector = visit o.right, collector
291
- collector << ")"
300
+ collector << ')'
292
301
  collector << " * (INTERVAL '1' #{DATE_MAPPING[o.left[0..-2]]})"
293
302
  return collector
294
303
  end
295
304
  end
296
305
  collector << "EXTRACT(#{DATE_MAPPING[o.left]} FROM CAST("
297
306
  collector = visit o.right, collector
298
- collector << " AS TIMESTAMP WITH TIME ZONE))"
307
+ collector << ' AS TIMESTAMP WITH TIME ZONE))'
299
308
  collector << " * (INTERVAL '1' #{interval})" if interval && o.with_interval
300
309
  collector
301
310
  end
302
311
 
303
312
  def visit_ArelExtensions_Nodes_Locate o, collector
304
- collector << "POSITION("
313
+ collector << 'POSITION('
305
314
  collector = visit o.right, collector
306
- collector << " IN "
315
+ collector << ' IN '
307
316
  collector = visit o.left, collector
308
- collector << ")"
317
+ collector << ')'
309
318
  collector
310
319
  end
311
320
 
312
321
  def visit_ArelExtensions_Nodes_Substring o, collector
313
- collector << "SUBSTR("
322
+ collector << 'SUBSTR('
314
323
  o.expressions.each_with_index { |arg, i|
315
324
  collector << COMMA if i != 0
316
325
  collector = visit arg, collector
317
326
  }
318
- collector << ")"
327
+ collector << ')'
319
328
  collector
320
329
  end
321
330
 
322
331
  def visit_ArelExtensions_Nodes_RegexpReplace o, collector
323
- collector << "REGEXP_REPLACE("
332
+ collector << 'REGEXP_REPLACE('
324
333
  visit o.left, collector
325
334
  collector << Arel::Visitors::ToSql::COMMA
326
- tab = o.pattern.inspect+ 'g' # Make it always global
335
+ tab = o.pattern.inspect + 'g' # Make it always global
327
336
  pattern = tab.split('/')[1..-2].join('/')
328
337
  flags = tab.split('/')[-1]
329
- visit Arel::Nodes.build_quoted(pattern), collector
338
+ visit Arel.quoted(pattern), collector
330
339
  collector << Arel::Visitors::ToSql::COMMA
331
340
  visit o.substitute, collector
332
341
  collector << Arel::Visitors::ToSql::COMMA
333
- visit Arel::Nodes.build_quoted(flags+"g"), collector
334
- collector << ")"
342
+ visit Arel.quoted(flags + 'g'), collector
343
+ collector << ')'
335
344
  collector
336
345
  end
337
346
 
@@ -342,57 +351,59 @@ module ArelExtensions
342
351
  end
343
352
 
344
353
  def visit_ArelExtensions_Nodes_IsNotNull o, collector
345
- collector = visit o.expr, collector
354
+ collector = visit o.expr, collector
346
355
  collector << ' IS NOT NULL'
347
356
  collector
348
357
  end
349
358
 
350
359
  def visit_ArelExtensions_Nodes_Sum o, collector
351
- collector << "sum("
360
+ collector << 'sum('
352
361
  collector = visit o.expr, collector
353
- collector << ")"
362
+ collector << ')'
354
363
  visit_Aggregate_For_AggregateFunction o, collector
355
364
  collector
356
365
  end
357
366
 
358
367
  def visit_ArelExtensions_Nodes_Wday o, collector
359
- collector << "EXRTACT(DOW, "
368
+ collector << 'EXRTACT(DOW, '
360
369
  collector = visit o.date, collector
361
370
  collector << ')'
362
371
  collector
363
372
  end
364
373
 
365
374
  def visit_ArelExtensions_Nodes_Cast o, collector
366
- as_attr = case o.as_attr
367
- when :string
368
- Arel::Nodes::SqlLiteral.new('varchar')
369
- when :text, :ntext
370
- Arel::Nodes::SqlLiteral.new('text')
371
- when :time
372
- Arel::Nodes::SqlLiteral.new('time')
373
- when :int
374
- collector << "CAST(CAST("
375
- collector = visit o.left, collector
376
- collector << " AS numeric) AS int)"
377
- return collector
378
- when :number, :decimal, :float
379
- Arel::Nodes::SqlLiteral.new('numeric')
380
- when :datetime
381
- Arel::Nodes::SqlLiteral.new('timestamp with time zone')
382
- when :date
383
- Arel::Nodes::SqlLiteral.new('date')
384
- when :binary
385
- Arel::Nodes::SqlLiteral.new('binary')
386
- when :jsonb
387
- Arel::Nodes::SqlLiteral.new('jsonb')
388
- else
389
- Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
390
- end
391
- collector << "CAST("
375
+ as_attr =
376
+ case o.as_attr
377
+ when :string
378
+ 'varchar'
379
+ when :text, :ntext
380
+ 'text'
381
+ when :time
382
+ 'time'
383
+ when :int
384
+ collector << 'CAST(CAST('
385
+ collector = visit o.left, collector
386
+ collector << ' AS numeric) AS int)'
387
+ return collector
388
+ when :number, :decimal, :float
389
+ 'numeric'
390
+ when :datetime
391
+ 'timestamp with time zone'
392
+ when :date
393
+ 'date'
394
+ when :binary
395
+ 'binary'
396
+ when :jsonb
397
+ 'jsonb'
398
+ else
399
+ o.as_attr.to_s
400
+ end
401
+
402
+ collector << 'CAST('
392
403
  collector = visit o.left, collector
393
- collector << " AS "
394
- collector = visit as_attr, collector
395
- collector << ")"
404
+ collector << ' AS '
405
+ collector = visit Arel::Nodes::SqlLiteral.new(as_attr), collector
406
+ collector << ')'
396
407
  collector
397
408
  end
398
409
 
@@ -401,9 +412,9 @@ module ArelExtensions
401
412
  comma = o.precision == 0 ? '' : (NUMBER_COMMA_MAPPING[o.locale][0] || '.')
402
413
  thousand_separator = NUMBER_COMMA_MAPPING[o.locale][1] || (NUMBER_COMMA_MAPPING[o.locale] ? '' : 'G')
403
414
  nines_after = (1..o.precision).map{'9'}.join('')
404
- nines_before = ("999#{thousand_separator}"*4+"990")
415
+ nines_before = ("999#{thousand_separator}" * 4 + '990')
405
416
 
406
- sign = ArelExtensions::Nodes::Case.new.when(col<0).
417
+ sign = Arel.when(col < 0).
407
418
  then('-').
408
419
  else(o.flags.include?('+') ? '+' : (o.flags.include?(' ') ? ' ' : ''))
409
420
  sign_length = ArelExtensions::Nodes::Length.new([sign])
@@ -411,35 +422,35 @@ module ArelExtensions
411
422
  number =
412
423
  if o.scientific_notation
413
424
  ArelExtensions::Nodes::Concat.new([
414
- Arel::Nodes::NamedFunction.new('TRIM',[
415
- Arel::Nodes::NamedFunction.new('TO_CHAR',[
416
- Arel.when(col.not_eq 0).then(col.abs/Arel::Nodes.build_quoted(10).pow(col.abs.log10.floor)).else(1),
417
- Arel::Nodes.build_quoted('FM'+nines_before+'"'+comma+'"V'+nines_after)
425
+ Arel::Nodes::NamedFunction.new('TRIM', [
426
+ Arel::Nodes::NamedFunction.new('TO_CHAR', [
427
+ Arel.when(col.not_eq 0).then(col.abs / Arel.quoted(10).pow(col.abs.log10.floor)).else(1),
428
+ Arel.quoted('FM' + nines_before + '"' + comma + '"V' + nines_after)
418
429
  ])]),
419
430
  o.type,
420
- Arel::Nodes::NamedFunction.new('TRIM',[
421
- Arel::Nodes::NamedFunction.new('TO_CHAR',[
431
+ Arel::Nodes::NamedFunction.new('TRIM', [
432
+ Arel::Nodes::NamedFunction.new('TO_CHAR', [
422
433
  Arel.when(col.not_eq 0).then(col.abs.log10.floor).else(0),
423
- Arel::Nodes.build_quoted('FM'+nines_before)
434
+ Arel.quoted('FM' + nines_before)
424
435
  ])])
425
436
  ])
426
437
  else
427
- Arel::Nodes::NamedFunction.new('TRIM',[
428
- Arel::Nodes::NamedFunction.new('TO_CHAR',[
429
- Arel::Nodes.build_quoted(col.abs),
430
- Arel::Nodes.build_quoted('FM'+nines_before+'"'+comma+'"V'+nines_after)
438
+ Arel::Nodes::NamedFunction.new('TRIM', [
439
+ Arel::Nodes::NamedFunction.new('TO_CHAR', [
440
+ Arel.quoted(col.abs),
441
+ Arel.quoted('FM' + nines_before + '"' + comma + '"V' + nines_after)
431
442
  ])])
432
443
  end
433
444
 
434
- repeated_char = (o.width == 0) ? Arel::Nodes.build_quoted('') : ArelExtensions::Nodes::Case.new().
435
- when(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length)>0).
436
- then(Arel::Nodes.build_quoted(
445
+ repeated_char = (o.width == 0) ? Arel.quoted('') : ArelExtensions::Nodes::Case.new.
446
+ when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0).
447
+ then(Arel.quoted(
437
448
  o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
438
- ).repeat(Arel::Nodes.build_quoted(o.width).abs-(number.length+sign_length))
449
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
439
450
  ).
440
451
  else('')
441
- before = (!o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
442
- middle = (o.flags.include?('0'))&&(!o.flags.include?('-')) ? repeated_char : ''
452
+ before = (!o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
453
+ middle = (o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
443
454
  after = o.flags.include?('-') ? repeated_char : ''
444
455
  full_number = ArelExtensions::Nodes::Concat.new([
445
456
  before,
@@ -448,7 +459,7 @@ module ArelExtensions
448
459
  number,
449
460
  after
450
461
  ])
451
- collector = visit ArelExtensions::Nodes::Concat.new([Arel::Nodes.build_quoted(o.prefix),full_number,Arel::Nodes.build_quoted(o.suffix)]), collector
462
+ collector = visit ArelExtensions::Nodes::Concat.new([Arel.quoted(o.prefix), full_number, Arel.quoted(o.suffix)]), collector
452
463
  collector
453
464
  end
454
465
 
@@ -460,7 +471,7 @@ module ArelExtensions
460
471
  o = o.dup
461
472
  o.orders = []
462
473
  end
463
- old_visit_Arel_Nodes_SelectStatement(o,collector)
474
+ old_visit_Arel_Nodes_SelectStatement(o, collector)
464
475
  end
465
476
 
466
477
  alias_method(:old_visit_Arel_Nodes_TableAlias, :visit_Arel_Nodes_TableAlias) rescue nil
@@ -468,7 +479,7 @@ module ArelExtensions
468
479
  if o.name.length > 63
469
480
  o = Arel::Table.new(o.table_name).alias(Arel.shorten(o.name))
470
481
  end
471
- old_visit_Arel_Nodes_TableAlias(o,collector)
482
+ old_visit_Arel_Nodes_TableAlias(o, collector)
472
483
  end
473
484
 
474
485
  alias_method(:old_visit_Arel_Attributes_Attribute, :visit_Arel_Attributes_Attribute) rescue nil
@@ -481,26 +492,26 @@ module ArelExtensions
481
492
  end
482
493
 
483
494
  def visit_ArelExtensions_Nodes_Std o, collector
484
- collector << (o.unbiased_estimator ? "STDDEV_SAMP(" : "STDDEV_POP(")
495
+ collector << (o.unbiased_estimator ? 'STDDEV_SAMP(' : 'STDDEV_POP(')
485
496
  visit o.left, collector
486
- collector << ")"
497
+ collector << ')'
487
498
  visit_Aggregate_For_AggregateFunction o, collector
488
499
  collector
489
500
  end
490
501
 
491
502
  def visit_ArelExtensions_Nodes_Variance o, collector
492
- collector << (o.unbiased_estimator ? "VAR_SAMP(" : "VAR_POP(")
503
+ collector << (o.unbiased_estimator ? 'VAR_SAMP(' : 'VAR_POP(')
493
504
  visit o.left, collector
494
- collector << ")"
505
+ collector << ')'
495
506
  visit_Aggregate_For_AggregateFunction o, collector
496
507
  collector
497
508
  end
498
509
 
499
- def visit_ArelExtensions_Nodes_Json o,collector
510
+ def visit_ArelExtensions_Nodes_Json o, collector
500
511
  case o.dict
501
512
  when Array
502
513
  collector << 'to_jsonb(array['
503
- o.dict.each.with_index do |v,i|
514
+ o.dict.each.with_index do |v, i|
504
515
  if i != 0
505
516
  collector << Arel::Visitors::MySQL::COMMA
506
517
  end
@@ -509,7 +520,7 @@ module ArelExtensions
509
520
  collector << '])'
510
521
  when Hash
511
522
  collector << 'jsonb_build_object('
512
- o.dict.each.with_index do |(k,v),i|
523
+ o.dict.each.with_index do |(k, v), i|
513
524
  if i != 0
514
525
  collector << Arel::Visitors::MySQL::COMMA
515
526
  end
@@ -518,11 +529,11 @@ module ArelExtensions
518
529
  collector = visit v, collector
519
530
  end
520
531
  collector << ')'
521
- when String,Numeric,TrueClass,FalseClass
522
- collector = visit Arel::Nodes.build_quoted("#{o.dict}"), collector
532
+ when String, Numeric, TrueClass, FalseClass
533
+ collector = visit Arel.quoted("#{o.dict}"), collector
523
534
  collector << '::jsonb'
524
535
  when NilClass
525
- collector << %Q['null'::jsonb]
536
+ collector << %Q['null'::jsonb]
526
537
  else
527
538
  collector = visit o.dict, collector
528
539
  collector << '::jsonb'
@@ -530,8 +541,8 @@ module ArelExtensions
530
541
  collector
531
542
  end
532
543
 
533
- def visit_ArelExtensions_Nodes_JsonMerge o,collector
534
- o.expressions.each.with_index do |v,i|
544
+ def visit_ArelExtensions_Nodes_JsonMerge o, collector
545
+ o.expressions.each.with_index do |v, i|
535
546
  if i != 0
536
547
  collector << ' || '
537
548
  end
@@ -540,14 +551,14 @@ module ArelExtensions
540
551
  collector
541
552
  end
542
553
 
543
- def visit_ArelExtensions_Nodes_JsonGet o,collector
554
+ def visit_ArelExtensions_Nodes_JsonGet o, collector
544
555
  collector = visit o.dict, collector
545
556
  collector << ' ->> '
546
557
  collector = visit o.key, collector
547
558
  collector
548
559
  end
549
560
 
550
- def visit_ArelExtensions_Nodes_JsonSet o,collector
561
+ def visit_ArelExtensions_Nodes_JsonSet o, collector
551
562
  collector << 'jsonb_set('
552
563
  collector = visit o.dict, collector
553
564
  collector << Arel::Visitors::MySQL::COMMA
@@ -569,7 +580,7 @@ module ArelExtensions
569
580
  else
570
581
  case o.dict
571
582
  when Hash
572
- o.dict.each.with_index do |(k,v),i|
583
+ o.dict.each.with_index do |(k, v), i|
573
584
  if i != 0
574
585
  collector << ' || '
575
586
  end