arel_extensions 1.3.8 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.gitignore +6 -7
  4. data/.rubocop.yml +3 -67
  5. data/.travis/oracle/download.js +152 -0
  6. data/.travis/oracle/download.sh +30 -0
  7. data/.travis/oracle/download_ojdbc.js +116 -0
  8. data/.travis/oracle/install.sh +34 -0
  9. data/.travis/setup_accounts.sh +9 -0
  10. data/.travis/sqlite3/extension-functions.sh +6 -0
  11. data/.travis.yml +223 -0
  12. data/Gemfile +21 -16
  13. data/README.md +90 -282
  14. data/Rakefile +30 -48
  15. data/TODO +1 -0
  16. data/appveyor.yml +22 -60
  17. data/arel_extensions.gemspec +14 -13
  18. data/functions.html +3 -3
  19. data/gemfiles/rails3.gemfile +10 -10
  20. data/gemfiles/rails4.gemfile +29 -0
  21. data/gemfiles/rails5_0.gemfile +29 -0
  22. data/gemfiles/rails5_1_4.gemfile +14 -14
  23. data/gemfiles/rails5_2.gemfile +14 -16
  24. data/init/mssql.sql +4 -4
  25. data/init/mysql.sql +38 -38
  26. data/init/oracle.sql +0 -0
  27. data/init/postgresql.sql +21 -21
  28. data/init/sqlite.sql +0 -0
  29. data/lib/arel_extensions/attributes.rb +3 -4
  30. data/lib/arel_extensions/boolean_functions.rb +14 -53
  31. data/lib/arel_extensions/common_sql_functions.rb +17 -16
  32. data/lib/arel_extensions/comparators.rb +28 -27
  33. data/lib/arel_extensions/date_duration.rb +13 -17
  34. data/lib/arel_extensions/insert_manager.rb +15 -18
  35. data/lib/arel_extensions/math.rb +53 -55
  36. data/lib/arel_extensions/math_functions.rb +39 -46
  37. data/lib/arel_extensions/nodes/abs.rb +1 -0
  38. data/lib/arel_extensions/nodes/blank.rb +2 -1
  39. data/lib/arel_extensions/nodes/case.rb +19 -20
  40. data/lib/arel_extensions/nodes/cast.rb +8 -10
  41. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  42. data/lib/arel_extensions/nodes/coalesce.rb +4 -3
  43. data/lib/arel_extensions/nodes/collate.rb +10 -9
  44. data/lib/arel_extensions/nodes/concat.rb +18 -9
  45. data/lib/arel_extensions/nodes/date_diff.rb +26 -42
  46. data/lib/arel_extensions/nodes/duration.rb +3 -0
  47. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  48. data/lib/arel_extensions/nodes/floor.rb +1 -1
  49. data/lib/arel_extensions/nodes/format.rb +8 -35
  50. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  51. data/lib/arel_extensions/nodes/function.rb +37 -42
  52. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  53. data/lib/arel_extensions/nodes/json.rb +39 -52
  54. data/lib/arel_extensions/nodes/length.rb +0 -5
  55. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  56. data/lib/arel_extensions/nodes/locate.rb +2 -1
  57. data/lib/arel_extensions/nodes/log10.rb +2 -1
  58. data/lib/arel_extensions/nodes/matches.rb +7 -5
  59. data/lib/arel_extensions/nodes/md5.rb +1 -0
  60. data/lib/arel_extensions/nodes/power.rb +5 -5
  61. data/lib/arel_extensions/nodes/rand.rb +1 -0
  62. data/lib/arel_extensions/nodes/repeat.rb +5 -3
  63. data/lib/arel_extensions/nodes/replace.rb +8 -16
  64. data/lib/arel_extensions/nodes/round.rb +6 -5
  65. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  66. data/lib/arel_extensions/nodes/std.rb +21 -18
  67. data/lib/arel_extensions/nodes/substring.rb +16 -8
  68. data/lib/arel_extensions/nodes/then.rb +1 -1
  69. data/lib/arel_extensions/nodes/trim.rb +6 -4
  70. data/lib/arel_extensions/nodes/union.rb +8 -5
  71. data/lib/arel_extensions/nodes/union_all.rb +7 -4
  72. data/lib/arel_extensions/nodes/wday.rb +4 -0
  73. data/lib/arel_extensions/nodes.rb +1 -1
  74. data/lib/arel_extensions/null_functions.rb +5 -19
  75. data/lib/arel_extensions/predications.rb +43 -44
  76. data/lib/arel_extensions/railtie.rb +5 -5
  77. data/lib/arel_extensions/set_functions.rb +7 -5
  78. data/lib/arel_extensions/string_functions.rb +29 -59
  79. data/lib/arel_extensions/tasks.rb +6 -6
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
  82. data/lib/arel_extensions/visitors/mssql.rb +180 -375
  83. data/lib/arel_extensions/visitors/mysql.rb +212 -350
  84. data/lib/arel_extensions/visitors/oracle.rb +178 -220
  85. data/lib/arel_extensions/visitors/oracle12.rb +31 -18
  86. data/lib/arel_extensions/visitors/postgresql.rb +173 -256
  87. data/lib/arel_extensions/visitors/sqlite.rb +126 -140
  88. data/lib/arel_extensions/visitors/to_sql.rb +237 -298
  89. data/lib/arel_extensions/visitors.rb +58 -82
  90. data/lib/arel_extensions.rb +31 -182
  91. data/test/database.yml +7 -15
  92. data/test/helper.rb +18 -0
  93. data/test/real_db_test.rb +116 -105
  94. data/test/support/fake_record.rb +3 -3
  95. data/test/test_comparators.rb +17 -14
  96. data/test/visitors/test_bulk_insert_oracle.rb +11 -11
  97. data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
  98. data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
  99. data/test/visitors/test_oracle.rb +55 -55
  100. data/test/visitors/test_to_sql.rb +226 -419
  101. data/test/with_ar/all_agnostic_test.rb +365 -709
  102. data/test/with_ar/insert_agnostic_test.rb +21 -27
  103. data/test/with_ar/test_bulk_sqlite.rb +16 -17
  104. data/test/with_ar/test_math_sqlite.rb +26 -26
  105. data/test/with_ar/test_string_mysql.rb +33 -31
  106. data/test/with_ar/test_string_sqlite.rb +34 -30
  107. metadata +34 -33
  108. data/.github/workflows/ruby.yml +0 -360
  109. data/NEWS.md +0 -32
  110. data/dev/compose.yaml +0 -29
  111. data/gemfiles/rails4_2.gemfile +0 -38
  112. data/gemfiles/rails5.gemfile +0 -29
  113. data/gemfiles/rails6.gemfile +0 -30
  114. data/gemfiles/rails6_1.gemfile +0 -30
  115. data/gemfiles/rails7.gemfile +0 -23
  116. data/gemfiles/rails7_1.gemfile +0 -22
  117. data/gemspecs/arel_extensions-v1.gemspec +0 -27
  118. data/gemspecs/arel_extensions-v2.gemspec +0 -27
  119. data/generate_gems.sh +0 -15
  120. data/lib/arel_extensions/aliases.rb +0 -14
  121. data/lib/arel_extensions/helpers.rb +0 -57
  122. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  123. data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
  124. data/lib/arel_extensions/nodes/rollup.rb +0 -36
  125. data/lib/arel_extensions/nodes/select.rb +0 -10
  126. data/lib/arel_extensions/nodes/sum.rb +0 -7
  127. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  128. data/test/arelx_test_helper.rb +0 -67
  129. data/version_v1.rb +0 -3
  130. data/version_v2.rb +0 -3
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  # Arel Extensions
2
2
 
3
- ![GitHub workflow](https://github.com/Faveod/arel-extensions/actions/workflows/ruby.yml/badge.svg)
4
- [![AppVeyor Build Status](https://img.shields.io/appveyor/ci/jdelporte/arel-extensions.svg?label=AppVeyor%20build)](https://ci.appveyor.com/project/jdelporte/arel-extensions)
3
+ [![Travis Build Status](https://img.shields.io/travis/Faveod/arel-extensions.svg?label=Travis%20build)](http://travis-ci.org/Faveod/arel-extensions)
4
+ [![AppVeyor Build Status](https://img.shields.io/appveyor/ci/yazfav/arel-extensions.svg?label=AppVeyor%20build)](https://ci.appveyor.com/project/yazfav/arel-extensions)
5
+ [![Security](https://hakiri.io/github/Faveod/arel-extensions/master.svg)](https://hakiri.io/github/Faveod/arel-extensions/master)
5
6
  ![](http://img.shields.io/badge/license-MIT-brightgreen.svg)
6
7
 
7
8
  Gem: [![Latest Release](https://img.shields.io/gem/v/arel_extensions.svg)](https://rubygems.org/gems/arel_extensions)
8
9
  [![Gem](https://ruby-gem-downloads-badge.herokuapp.com/arel_extensions?type=total)](https://rubygems.org/gems/arel_extensions)
9
10
  [![Gem](https://ruby-gem-downloads-badge.herokuapp.com/arel_extensions?label=downloads-current-version)](https://rubygems.org/gems/arel_extensions)
10
11
 
11
- Arel Extensions adds shortcuts, fixes and new ORM mappings (Ruby to SQL) to Arel.
12
- It aims to ensure pure Ruby syntax for most usual cases.
12
+ Arel Extensions adds shortcuts, fixes and new ORM mappings (ruby to SQL) to Arel.
13
+ It aims to ensure pure ruby syntax for the biggest number of usual cases.
13
14
  It allows to use more advanced SQL functions for any supported RDBMS.
14
15
 
15
16
 
@@ -18,11 +19,6 @@ It allows to use more advanced SQL functions for any supported RDBMS.
18
19
  Arel 6 (Rails 4) or Arel 7+ (Rails 5).
19
20
  [Arel Repository](http://github.com/rails/arel)
20
21
 
21
- or
22
-
23
- Rails 6
24
- [Rails Repository](http://github.com/rails/rails)
25
-
26
22
  ## Usage
27
23
 
28
24
  Most of the features will work just by adding the gem to your Gemfiles. To make sure to get all the features for any dbms, you should execute the next line as soon as you get your connection to your DB:
@@ -36,8 +32,7 @@ It will add common SQL features in your DB to align ti with current routines. Te
36
32
 
37
33
  ## Examples
38
34
 
39
- In the following examples
40
- `t` is an `Arel::Table` for table `my_table` (i.e., `t = Arel::Table.new('my_table')`).
35
+ t is an Arel::Table for table my_table
41
36
 
42
37
  ## Comparators
43
38
 
@@ -51,7 +46,7 @@ In the following examples
51
46
  # => my_table.nb > 42
52
47
  ```
53
48
 
54
- Other operators: <, >=, <=, =~
49
+ Other operators : <, >=, <=, =~
55
50
 
56
51
 
57
52
  ## Maths
@@ -74,12 +69,12 @@ With Arel Extensions:
74
69
  # => SUM(my_table.nb) + 42
75
70
  ```
76
71
 
77
- Other functions: ABS, RAND, ROUND, FLOOR, CEIL, FORMAT
72
+ Other functions : ABS, RAND, ROUND, FLOOR, CEIL, FORMAT
78
73
 
79
74
  For Example:
80
- ```ruby
75
+ ```ruby
81
76
  t[:price].format_number("%07.2f €","fr_FR")
82
- # equivalent to 'sprintf("%07.2f €",price)' plus locale management
77
+ # equivalent to 'sprintf("%07.2f €",price)' plus locale management
83
78
  ```
84
79
 
85
80
  ## String operations
@@ -95,29 +90,14 @@ t[:price].format_number("%07.2f €","fr_FR")
95
90
  # => TRIM(TRIM(TRIM(COALESCE(my_table.name, '')), '\t'), '\n') = ''
96
91
 
97
92
  (t[:name] =~ /\A[a-d_]+/).to_sql
98
- # => my_table.name REGEXP '^[a-d_]+'
99
- ```
100
-
101
- The `replace` function supports string and regex patterns.
102
- For instance
103
-
104
- ```ruby
105
- t[:email].replace('@', ' at ').replace('.', ' dot ').to_sql
106
- # => REPLACE(REPLACE(`my_table`.`email`, '@', ' at '), '.', ' dot ')
93
+ # => my_table.name REGEXP '\^[a-d_]+'
107
94
  ```
108
95
 
109
- Captures are supported when using regex patterns. The replace string may then reference the capture groups using `\1`, `\2`, etc. For instance
110
-
111
- ```ruby
112
- t[:email].replace(/^(.*)@(.*)$/, 'user: \1, host: \2').to_sql
113
- # => REGEXP_REPLACE(`my_table`.`email`, '(?-mix:^(.*)@(.*)$)', 'user: \\1, host: \\2')
114
- ```
115
-
116
- Other functions: SOUNDEX, LENGTH, REPLACE, LOCATE, SUBSTRING, TRIM
96
+ Other functions : SOUNDEX, LENGTH, REPLACE, LOCATE, SUBSTRING, TRIM
117
97
 
118
98
  ### String Array operations
119
99
 
120
- `t[:list]` is a classical varchar containing a comma separated list (`"1,2,3,4"`).
100
+ ```t[:list]``` is a classical varchar containing a comma separated list ("1,2,3,4")
121
101
 
122
102
  ```ruby
123
103
  (t[:list] & 3).to_sql
@@ -145,77 +125,12 @@ t[:birthdate].month.to_sql
145
125
 
146
126
  t[:birthdate].year.to_sql
147
127
  # => YEAR(my_table.birthdate)
148
- ```
149
-
150
- ### Datetime
151
-
152
- ```ruby
153
- # datetime difference
154
- t[:birthdate] - Time.utc(2014, 3, 3, 12, 41, 18)
155
128
 
156
- # comparison
157
- t[:birthdate] >= '2014-03-03 10:10:10'
158
- ```
159
-
160
- ### Format and Time Zone Conversion
161
-
162
- `format` has two forms:
163
-
164
- ```ruby
165
129
  t[:birthdate].format('%Y-%m-%d').to_sql
166
130
  # => DATE_FORMAT(my_table.birthdate, '%Y-%m-%d')
167
131
  ```
168
132
 
169
- Which formats the datetime without any time zone conversion.
170
- The second form accepts 2 kinds of values:
171
-
172
- 1. String:
173
-
174
- ```ruby
175
- t[:birthdate].format('%Y/%m/%d %H:%M:%S', 'posix/Pacific/Tahiti')
176
- # => DATE_FORMAT(CONVERT_TZ(CAST(my_table.birthdate AS datetime), 'UTC', 'posix/Pacific/Tahiti'), '%Y/%m/%d %H:%i:%S') ## MySQL
177
- # => TO_CHAR(CAST(my_table.birthdate AS timestamp with time zone) AT TIME ZONE 'posix/Pacific/Tahiti', 'YYYY/MM/DD HH24:MI:SS') ## PostgreSQL
178
- # => CONVERT(datetime, my_table.birthdate) AT TIME ZONE 'UTC' AT TIME ZONE N'posix/Pacific/Tahiti' ## SQL Server (& truncated for clarity)
179
- # ^^^^^^^^^^^^^^^^^^^^ 🚨 Invalid timezone for SQL Server. Explanation below.
180
- ```
181
-
182
- which will convert the datetime field to the supplied time zone. This generally
183
- means that you're letting the RDBMS decide or infer what is the timezone of the
184
- column before conversion to the supplied timezone.
185
-
186
- 1. Hash of the form `{ src_time_zone => dst_time_zone }`:
187
-
188
- ```ruby
189
- t[:birthdate].format('%Y/%m/%d %H:%M:%S', { 'posix/Europe/Paris' => 'posix/Pacific/Tahiti' })
190
- ```
191
-
192
- which will explicitly indicate the original timestamp that should be considered
193
- by the RDBMS.
194
-
195
- Warning:
196
-
197
- - ⚠️ Time Zone names are specific to each RDBMS. While `PostgreSQL` and `MySQL`
198
- have overlaping names (the ones prefixed with `posix`), you should always
199
- read your vendor's documentation. `SQL Server` is a black sheep and has its
200
- own conventions.
201
- - ⚠️ Daylight saving is managed by the RDBMS vendor. Choose the approptiate time
202
- zone name that enforces proper daylight saving conversions.
203
- - ☣️ Choosing `GMT+offset` will certainly bypass daylight saving computations.
204
- - ☣️ Choosing abbreviate forms like `CET`, which stands for `Central European
205
- Time` will behave differently on `PostgreSQL` and `MySQL`. Don't assume
206
- uniform behavior, or even a _rational_ one.
207
- - ⚠️ Pay attention to the type of the `datetime` column you're working with. For
208
- example, in Postgres, a `datetime` can be one of the following types:
209
- 1. `timestamp with time zone`
210
- 2. `timestamp without time zone`
211
- In the first case, you don't need to supply a conversion hash because postgres
212
- knows how to convert it to the desired time zone. However, if you do the same
213
- for the second case, you might get surprises, especially if your Postgres
214
- installation's default timezone is not `UTC`.
215
- - ⚠️ SQLite is not supported.
216
- - 🚨 Always test against your setup 🚨
217
-
218
- ## Unions
133
+ ## Unions
219
134
 
220
135
  ```ruby
221
136
  (t.where(t[:name].eq('str')) + t.where(t[:name].eq('test'))).to_sql
@@ -228,7 +143,7 @@ Arel-extensions allows to use functions on case clause
228
143
 
229
144
  ```ruby
230
145
  t[:name].when("smith").then(1).when("doe").then(2).else(0).sum.to_sql
231
- # => SUM(CASE "my_table"."name" WHEN 'smith' THEN 1 WHEN 'doe' THEN 2 ELSE 0 END)
146
+ # => SUM(CASE "my_table"."name" WHEN 'smith' THEN 1 WHEN 'doe' THEN 2 ELSE 0 END)
232
147
  ```
233
148
 
234
149
  ## Cast Function
@@ -244,15 +159,15 @@ t[:id].cast('char').to_sql
244
159
  ## Stored Procedures and User-defined functions
245
160
 
246
161
  To optimize queries, some classical functions are defined in databases missing any alternative native functions.
247
- Examples:
248
- - `FIND_IN_SET`
162
+ Examples :
163
+ - FIND_IN_SET
249
164
 
250
165
  ## BULK INSERT / UPSERT
251
166
 
252
167
  Arel Extensions improves InsertManager by adding bulk_insert method, which allows to insert multiple rows in one insert.
253
168
 
254
169
 
255
- ```ruby
170
+ ```
256
171
  @cols = ['id', 'name', 'comments', 'created_at']
257
172
  @data = [
258
173
  [23, 'name1', "sdfdsfdsfsdf", '2016-01-01'],
@@ -294,7 +209,7 @@ User.connection.execute(insert_manager.to_sql)
294
209
  <td class="tg-yw4l">CEIL<br>column.ceil</td>
295
210
  <td class="ok">✔</td>
296
211
  <td class="ok">✔</td>
297
- <td class="tg-j6lv">CASE + CAST</td>
212
+ <td class="tg-j6lv">CASE + ROUND</td>
298
213
  <td class="ok">✔</td>
299
214
  <td class="tg-j6lv">CEILING()</td>
300
215
  <td class="tg-j6lv">CEILING()</td>
@@ -303,20 +218,11 @@ User.connection.execute(insert_manager.to_sql)
303
218
  <td class="tg-yw4l">FLOOR<br>column.floor</td>
304
219
  <td class="ok">✔</td>
305
220
  <td class="ok">✔</td>
306
- <td class="tg-j6lv">CASE + CAST</td>
221
+ <td class="tg-j6lv">CASE + ROUND</td>
307
222
  <td class="ok">✔</td>
308
223
  <td class="ok">✔</td>
309
224
  <td class="ok">✔</td>
310
225
  </tr>
311
- <tr>
312
- <td class="tg-yw4l">POSIX FORMATTING<br>column.format_number("$ %7.2f","en_US")</td>
313
- <td class="ok">✔</td>
314
- <td class="ok">✔</td>
315
- <td class="ok">✔</td>
316
- <td class="ok">✔</td>
317
- <td class="ok">✔</td>
318
- <td class="ko">not implemented</td>
319
- </tr>
320
226
  <tr>
321
227
  <td class="tg-yw4l">RAND<br>Arel.rand</td>
322
228
  <td class="ok">✔</td>
@@ -345,32 +251,23 @@ User.connection.execute(insert_manager.to_sql)
345
251
  <td class="ok">✔</td>
346
252
  </tr>
347
253
  <tr>
348
- <th class="tg-ffjm" rowspan="17"><div>String functions</div></th>
349
- <td class="tg-yw4l">CONCAT<br>column + "string"</td>
254
+ <td class="tg-yw4l">POSIX FORMATTING<br>column.format_number("$ %7.2f","en_US")</td>
255
+ <td class="ok">✔</td>
350
256
  <td class="ok">✔</td>
351
257
  <td class="ok">✔</td>
352
- <td class="tg-j6lv"> ||</td>
353
258
  <td class="ok">✔</td>
354
- <td class="tg-j6lv">+</td>
355
259
  <td class="ok">✔</td>
260
+ <td class="ko">not implemented</td>
356
261
  </tr>
357
262
  <tr>
358
- <td class="tg-yw4l">FIND_IN_SET<br>column &amp; ("l")</td>
359
- <td class="ok">✔</td>
360
- <td class="ok">✔</td>
361
- <td class="tg-orpl">Ruby function</td>
362
- <td class="ok">✔</td>
263
+ <th class="tg-ffjm" rowspan="17"><div>String functions</div></th>
264
+ <td class="tg-yw4l">CONCAT<br>column + "string"</td>
363
265
  <td class="ok">✔</td>
364
266
  <td class="ok">✔</td>
365
- </tr>
366
- <tr>
367
- <td class="tg-yw4l">ILIKE (in Arel6)<br/>column.imatches('%pattern')</td>
368
- <td class="tg-j6lv">LOWER() LIKE LOWER()</td>
267
+ <td class="tg-j6lv"> ||</td>
369
268
  <td class="ok">✔</td>
269
+ <td class="tg-j6lv">+</td>
370
270
  <td class="ok">✔</td>
371
- <td class="tg-j6lv">LOWER() LIKE LOWER()</td>
372
- <td class="tg-j6lv">LOWER() LIKE LOWER()</td>
373
- <td class="tg-j6lv">LOWER() LIKE LOWER()</td>
374
271
  </tr>
375
272
  <tr>
376
273
  <td class="tg-yw4l">LENGTH<br>column.length</td>
@@ -391,70 +288,34 @@ User.connection.execute(insert_manager.to_sql)
391
288
  <td class="ok">✔</td>
392
289
  </tr>
393
290
  <tr>
394
- <td class="tg-yw4l">Matching Accent/Case Insensitive<br>column.ai_imatches('blah')</td>
395
- <td class="ok">✔</td>
396
- <td class="tg-j6lv">unaccent required</td>
397
- <td class="tg-j6lv">not supported</td>
398
- <td class="ok">✔</td>
399
- <td class="tg-j6lv">✔</td>
400
- <td class="tg-j6lv">?</td>
401
- </tr>
402
- <tr>
403
- <td class="tg-yw4l">Matching Accent Insensitive<br>column.ai_matches('blah')</td>
404
- <td class="ok">not supported</td>
405
- <td class="tg-j6lv">not supported</td>
406
- <td class="tg-j6lv">not supported</td>
407
- <td class="ok">not supported</td>
408
- <td class="tg-j6lv">✔</td>
409
- <td class="tg-j6lv">?</td>
410
- </tr>
411
- <tr>
412
- <td class="tg-yw4l">Matching Case Insensitive<br>column.imatches('blah')</td>
413
- <td class="ok">not supported</td>
414
- <td class="tg-j6lv">✔</td>
415
- <td class="tg-j6lv">✔</td>
291
+ <td class="tg-yw4l">SUBSTRING<br/>column[1..2]<br/>column.substring(1)<br/>column.substring(1, 1)</td>
416
292
  <td class="ok">✔</td>
417
- <td class="tg-j6lv">✔</td>
418
- <td class="tg-j6lv">?</td>
419
- </tr>
420
- <tr>
421
- <td class="tg-yw4l">Matching Accent/Case Sensitive<br>column.smatches('blah')</td>
293
+ <td class="tg-j6lv">SUBSTR()</td>
294
+ <td class="tg-j6lv">SUBSTR()</td>
295
+ <td class="tg-j6lv">SUBSTR()</td>
422
296
  <td class="ok">✔</td>
423
- <td class="tg-j6lv">✔</td>
424
- <td class="tg-j6lv">not supported</td>
425
297
  <td class="ok">✔</td>
426
- <td class="tg-j6lv">✔</td>
427
- <td class="tg-j6lv">?</td>
428
298
  </tr>
429
299
  <tr>
430
- <td class="tg-yw4l">NOT_REGEXP<br>column != "pattern"</td>
300
+ <td class="tg-yw4l">FIND_IN_SET<br>column &amp; ("l")</td>
431
301
  <td class="ok">✔</td>
432
- <td class="ok">✔<br></td>
433
- <td class="tg-3oug">require pcre.so</td>
434
- <td class="tg-j6lv">NOT REGEXP_LIKE </td>
435
- <td class="tg-j6lv">NOT LIKE</td>
436
302
  <td class="ok">✔</td>
437
- </tr>
438
- <tr>
439
- <td class="tg-yw4l">REGEXP<br>column =~ "pattern"<br></td>
303
+ <td class="tg-orpl">Ruby function</td>
440
304
  <td class="ok">✔</td>
441
305
  <td class="ok">✔</td>
442
- <td class="tg-3oug">require pcre.so</td>
443
- <td class="tg-j6lv">REGEXP_LIKE</td>
444
- <td class="tg-j6lv">LIKE</td>
445
306
  <td class="ok">✔</td>
446
307
  </tr>
447
308
  <tr>
448
- <td class="tg-yw4l">REPLACE<br>column.replace("s","X")</td>
449
- <td class="ok">✔</td>
309
+ <td class="tg-yw4l">SOUNDEX<br>column.soundex</td>
450
310
  <td class="ok">✔</td>
311
+ <td class="tg-3oug">require fuzzystrmatch</td>
451
312
  <td class="ok">✔</td>
452
313
  <td class="ok">✔</td>
453
314
  <td class="ok">✔</td>
454
315
  <td class="ok">✔</td>
455
316
  </tr>
456
317
  <tr>
457
- <td class="tg-yw4l">REPLACE<br>column.replace(/re/,"X")</td>
318
+ <td class="tg-yw4l">REPLACE<br>column.replace("s","X")</td>
458
319
  <td class="ok">✔</td>
459
320
  <td class="ok">✔</td>
460
321
  <td class="ok">✔</td>
@@ -463,22 +324,31 @@ User.connection.execute(insert_manager.to_sql)
463
324
  <td class="ok">✔</td>
464
325
  </tr>
465
326
  <tr>
466
- <td class="tg-yw4l">SOUNDEX<br>column.soundex</td>
327
+ <td class="tg-yw4l">REGEXP<br>column =~ "pattern"<br></td>
467
328
  <td class="ok">✔</td>
468
- <td class="tg-3oug">require fuzzystrmatch</td>
469
329
  <td class="ok">✔</td>
330
+ <td class="tg-3oug">require pcre.so</td>
331
+ <td class="tg-j6lv">REGEXP_LIKE</td>
332
+ <td class="tg-j6lv">LIKE</td>
470
333
  <td class="ok">✔</td>
334
+ </tr>
335
+ <tr>
336
+ <td class="tg-yw4l">NOT_REGEXP<br>column != "pattern"</td>
471
337
  <td class="ok">✔</td>
338
+ <td class="ok">✔<br></td>
339
+ <td class="tg-3oug">require pcre.so</td>
340
+ <td class="tg-j6lv">NOT REGEXP_LIKE </td>
341
+ <td class="tg-j6lv">NOT LIKE</td>
472
342
  <td class="ok">✔</td>
473
343
  </tr>
474
344
  <tr>
475
- <td class="tg-yw4l">SUBSTRING<br/>column[1..2]<br/>column.substring(1)<br/>column.substring(1, 1)</td>
476
- <td class="ok">✔</td>
477
- <td class="tg-j6lv">SUBSTR()</td>
478
- <td class="tg-j6lv">SUBSTR()</td>
479
- <td class="tg-j6lv">SUBSTR()</td>
345
+ <td class="tg-yw4l">ILIKE (in Arel6)<br/>column.imatches('%pattern')</td>
346
+ <td class="tg-j6lv">LOWER() LIKE LOWER()</td>
480
347
  <td class="ok">✔</td>
481
348
  <td class="ok">✔</td>
349
+ <td class="tg-j6lv">LOWER() LIKE LOWER()</td>
350
+ <td class="tg-j6lv">LOWER() LIKE LOWER()</td>
351
+ <td class="tg-j6lv">LOWER() LIKE LOWER()</td>
482
352
  </tr>
483
353
  <tr>
484
354
  <td class="tg-yw4l">TRIM (leading)<br>column.trim("LEADING","M")</td>
@@ -507,6 +377,43 @@ User.connection.execute(insert_manager.to_sql)
507
377
  <td class="tg-j6lv">LTRIM(RTRIM())</td>
508
378
  <td class="tg-j6lv">TRIM()</td>
509
379
  </tr>
380
+ <tr>
381
+ <td class="tg-yw4l">Matching Accent/Case Insensitive<br>column.ai_imatches('blah')</td>
382
+ <td class="ok">✔</td>
383
+ <td class="tg-j6lv">unaccent required</td>
384
+ <td class="tg-j6lv">not supported</td>
385
+ <td class="ok">✔</td>
386
+ <td class="tg-j6lv">✔</td>
387
+ <td class="tg-j6lv">?</td>
388
+ </tr>
389
+ <tr>
390
+ <td class="tg-yw4l">Matching Accent Insensitive<br>column.ai_matches('blah')</td>
391
+ <td class="ok">not supported</td>
392
+ <td class="tg-j6lv">not supported</td>
393
+ <td class="tg-j6lv">not supported</td>
394
+ <td class="ok">not supported</td>
395
+ <td class="tg-j6lv">✔</td>
396
+ <td class="tg-j6lv">?</td>
397
+ </tr>
398
+ <tr>
399
+ <td class="tg-yw4l">Matching Case Insensitive<br>column.imatches('blah')</td>
400
+ <td class="ok">not supported</td>
401
+ <td class="tg-j6lv">✔</td>
402
+ <td class="tg-j6lv">✔</td>
403
+ <td class="ok">✔</td>
404
+ <td class="tg-j6lv">✔</td>
405
+ <td class="tg-j6lv">?</td>
406
+ </tr>
407
+ <tr>
408
+ <td class="tg-yw4l">Matching Accent/Case Sensitive<br>column.smatches('blah')</td>
409
+ <td class="ok">✔</td>
410
+ <td class="tg-j6lv">✔</td>
411
+ <td class="tg-j6lv">not supported</td>
412
+ <td class="ok">✔</td>
413
+ <td class="tg-j6lv">✔</td>
414
+ <td class="tg-j6lv">?</td>
415
+ </tr>
416
+
510
417
  <tr>
511
418
  <th class="tg-4rp9" rowspan="6"><div>Date functions</div></th>
512
419
  <td class="tg-yw4l">DATEADD<br>column + 2.year<br></td>
@@ -563,16 +470,7 @@ User.connection.execute(insert_manager.to_sql)
563
470
  <td class="ok">✔</td>
564
471
  </tr>
565
472
  <tr>
566
- <th class="tg-72dn" rowspan="13"><div>Comparators functions</div></th>
567
- <td class="tg-yw4l">BLANK<br>column.blank<br></td>
568
- <td class="ok">✔</td>
569
- <td class="ok">✔</td>
570
- <td class="ok">✔</td>
571
- <td class="ok">✔</td>
572
- <td class="ok">✔</td>
573
- <td class="ok">✔</td>
574
- </tr>
575
- <tr>
473
+ <th class="tg-72dn" rowspan="8"><div>Comparators functions</div></th>
576
474
  <td class="tg-yw4l">COALESCE<br>column.coalesce(var)</td>
577
475
  <td class="ok">✔</td>
578
476
  <td class="ok">✔</td>
@@ -581,24 +479,6 @@ User.connection.execute(insert_manager.to_sql)
581
479
  <td class="ok">✔</td>
582
480
  <td class="ok">✔</td>
583
481
  </tr>
584
- <tr>
585
- <td class="tg-yw4l">COALESCE_BLANK<br>column.coalesce_blank(var)</td>
586
- <td class="ok">✔</td>
587
- <td class="ok">✔</td>
588
- <td class="ok">✔</td>
589
- <td class="ok">✔</td>
590
- <td class="ok">✔</td>
591
- <td class="ok">✔</td>
592
- </tr>
593
- <tr>
594
- <td class="tg-yw4l">IF_PRESENT</td>
595
- <td class="ok">✔</td>
596
- <td class="ok">✔</td>
597
- <td class="ok">✔</td>
598
- <td class="ok">✔</td>
599
- <td class="ok">✔</td>
600
- <td class="ok">✔</td>
601
- </tr>
602
482
  <tr>
603
483
  <td class="tg-yw4l">ISNULL<br>column.isnull()</td>
604
484
  <td class="tg-j6lv">IFNULL()</td>
@@ -608,24 +488,6 @@ User.connection.execute(insert_manager.to_sql)
608
488
  <td class="ok">✔</td>
609
489
  <td class="ok">✔</td>
610
490
  </tr>
611
- <tr>
612
- <td class="tg-yw4l">NOT_BLANK<br>column.not_blank<br></td>
613
- <td class="ok">✔</td>
614
- <td class="ok">✔</td>
615
- <td class="ok">✔</td>
616
- <td class="ok">✔</td>
617
- <td class="ok">✔</td>
618
- <td class="ok">✔</td>
619
- </tr>
620
- <tr>
621
- <td class="tg-yw4l">PRESENT<br>column.present<br>alias to NOT_BLANK<br></td>
622
- <td class="ok">✔</td>
623
- <td class="ok">✔</td>
624
- <td class="ok">✔</td>
625
- <td class="ok">✔</td>
626
- <td class="ok">✔</td>
627
- <td class="ok">✔</td>
628
- </tr>
629
491
  <tr>
630
492
  <td class="tg-yw4l">==<br>column == integer</td>
631
493
  <td class="ok">✔</td>
@@ -729,57 +591,3 @@ User.connection.execute(insert_manager.to_sql)
729
591
  </tr>
730
592
  </tbody>
731
593
  </table>
732
-
733
- ## Version Compatibility
734
-
735
- <table>
736
- <tr><th>Ruby</th> <th>Rails</th> <th>Arel Extensions</th></tr>
737
- <tr><td>3.1</td> <td>6.1</td> <td>2</td></tr>
738
- <tr><td>3.0</td> <td>6.1</td> <td>2</td></tr>
739
- <tr><td>2.7</td> <td>6.1, 6.0</td> <td>2</td></tr>
740
- <tr><td>2.5</td> <td>6.1, 6.0</td> <td>2</td></tr>
741
- <tr><td>2.5</td> <td>5.2</td> <td>1</td></tr>
742
- </table>
743
-
744
- ## Development
745
-
746
- Let's say you want to develop/test for `ruby 2.7.5` and `rails 5.2`.
747
-
748
- You will need to fix your ruby version:
749
-
750
- ```bash
751
- rbenv install 2.7.5
752
- rbenv local 2.7.5
753
- ```
754
-
755
- Fix your gemfiles:
756
-
757
- ```bash
758
- bundle config set --local gemfile ./gemfiles/rails6.gemfile
759
- ```
760
-
761
- Install dependencies:
762
- ```bash
763
- bundle install
764
- ```
765
-
766
- Develop, then test:
767
-
768
- ```bash
769
- bundle exec rake test:to_sql
770
- ```
771
-
772
- Refer to the [Version Compatibility](#version-compatibility) section to correctly
773
- set your gemfile.
774
-
775
- ### MariaDB and Postgres
776
-
777
- We provide a `docker compose` to set up some databases for testing:
778
-
779
- ```bash
780
- docker-compose -f dev/compose.yaml up
781
- ```
782
-
783
- ⚠️ Note: localization tests will fail for postgresql because the image is made
784
- for `en_US.UTF`. We should fix it later, but for the time being the CI works
785
- correctly for these tests, so you can safely ignore them for the time being.
data/Rakefile CHANGED
@@ -1,57 +1,39 @@
1
1
  require 'bundler'
2
- Bundler::GemHelper.install_tasks name: 'arel_extensions'
2
+ Bundler::GemHelper.install_tasks :name => "arel_extensions"
3
3
 
4
4
  require 'rake/testtask'
5
5
 
6
- desc 'Default Task'
7
- task default: [:test]
6
+ desc "Default Task"
7
+ task default: [ :test ]
8
8
 
9
9
  Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.libs << 'test'
12
- t.pattern = 'test/**/test_*.rb'
13
- t.warning = true
14
- t.verbose = true
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/test_*.rb'
13
+ t.warning = true
14
+ t.verbose = true
15
15
  end
16
16
 
17
- namespace :test do
18
- Rake::TestTask.new('to_sql' => []) { |t|
19
- t.libs << 'lib'
20
- t.libs << 'test'
21
- t.pattern = 'test/visitors/test_to_sql.rb'
22
- t.warning = true
23
- t.verbose = true
24
- t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
25
- }
26
- end
27
-
28
- %w[mysql postgresql sqlite ibm_db oracle mssql].each do |adapter|
29
- namespace :test do
30
- Rake::TestTask.new(adapter => "#{adapter}:env") { |t|
31
- t.libs << 'lib'
32
- t.libs << 'test'
33
- t.pattern = 'test/with_ar/*_agnostic_test.rb'
34
- t.warning = false
35
- t.verbose = true
36
- t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
37
- }
38
- end
39
-
40
- namespace adapter do
41
- task test: "test_#{adapter}"
42
- task isolated_test: "isolated_test_#{adapter}"
43
-
44
- # Set the connection environment for the adapter
45
- task(:env) { ENV['DB'] = adapter }
46
- end
47
-
48
- # Make sure the adapter test evaluates the env setting task
49
- task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
50
- end
51
-
52
- # Useful shorthands.
53
- namespace :test do
54
- task :sql => :to_sql
55
- task :pg => :postgresql
56
- task :postgres => :postgresql
17
+ %w(mysql postgresql sqlite ibm_db oracle mssql).each do |adapter|
18
+ namespace :test do
19
+ Rake::TestTask.new(adapter => "#{adapter}:env") { |t|
20
+ t.libs << 'lib'
21
+ t.libs << 'test'
22
+ t.pattern = 'test/with_ar/*_agnostic_test.rb'
23
+ t.warning = true
24
+ t.verbose = true
25
+ t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
26
+ }
27
+ end
28
+
29
+ namespace adapter do
30
+ task :test => "test_#{adapter}"
31
+ task :isolated_test => "isolated_test_#{adapter}"
32
+
33
+ # Set the connection environment for the adapter
34
+ task(:env) { ENV['DB'] = adapter }
35
+ end
36
+
37
+ # Make sure the adapter test evaluates the env setting task
38
+ task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
57
39
  end
data/TODO CHANGED
@@ -1,6 +1,7 @@
1
1
  Code quality:
2
2
  + codeclimate.com
3
3
  + gemnasium
4
+ + appveyor.com (windows)
4
5
  + hakiri.io
5
6
  - coveralls.io
6
7
  - inch-ci.org