arel_extensions 1.4.2 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -1
- data/.gitignore +6 -7
- data/.rubocop.yml +3 -67
- data/.travis/oracle/download.js +152 -0
- data/.travis/oracle/download.sh +30 -0
- data/.travis/oracle/download_ojdbc.js +116 -0
- data/.travis/oracle/install.sh +34 -0
- data/.travis/setup_accounts.sh +9 -0
- data/.travis/sqlite3/extension-functions.sh +6 -0
- data/.travis.yml +223 -0
- data/Gemfile +28 -2
- data/README.md +90 -239
- data/Rakefile +30 -48
- data/TODO +1 -0
- data/appveyor.yml +22 -60
- data/arel_extensions.gemspec +14 -13
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +10 -10
- data/gemfiles/rails4.gemfile +29 -0
- data/gemfiles/rails5_0.gemfile +29 -0
- data/gemfiles/rails5_1_4.gemfile +14 -14
- data/gemfiles/rails5_2.gemfile +14 -16
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +21 -21
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -10
- data/lib/arel_extensions/boolean_functions.rb +14 -53
- data/lib/arel_extensions/common_sql_functions.rb +17 -16
- data/lib/arel_extensions/comparators.rb +28 -27
- data/lib/arel_extensions/date_duration.rb +13 -17
- data/lib/arel_extensions/insert_manager.rb +15 -18
- data/lib/arel_extensions/math.rb +53 -55
- data/lib/arel_extensions/math_functions.rb +39 -46
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +2 -1
- data/lib/arel_extensions/nodes/case.rb +19 -20
- data/lib/arel_extensions/nodes/cast.rb +8 -10
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/coalesce.rb +4 -3
- data/lib/arel_extensions/nodes/collate.rb +10 -9
- data/lib/arel_extensions/nodes/concat.rb +18 -9
- data/lib/arel_extensions/nodes/date_diff.rb +26 -42
- data/lib/arel_extensions/nodes/duration.rb +3 -0
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -35
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +37 -42
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +39 -52
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
- data/lib/arel_extensions/nodes/locate.rb +2 -1
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +7 -5
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +1 -0
- data/lib/arel_extensions/nodes/repeat.rb +5 -3
- data/lib/arel_extensions/nodes/replace.rb +8 -16
- data/lib/arel_extensions/nodes/round.rb +6 -5
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -8
- data/lib/arel_extensions/nodes/then.rb +1 -1
- data/lib/arel_extensions/nodes/trim.rb +6 -4
- data/lib/arel_extensions/nodes/union.rb +8 -5
- data/lib/arel_extensions/nodes/union_all.rb +7 -4
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +5 -19
- data/lib/arel_extensions/predications.rb +43 -44
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +7 -5
- data/lib/arel_extensions/string_functions.rb +29 -59
- data/lib/arel_extensions/tasks.rb +6 -6
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
- data/lib/arel_extensions/visitors/mssql.rb +191 -422
- data/lib/arel_extensions/visitors/mysql.rb +212 -350
- data/lib/arel_extensions/visitors/oracle.rb +178 -220
- data/lib/arel_extensions/visitors/oracle12.rb +31 -18
- data/lib/arel_extensions/visitors/postgresql.rb +173 -256
- data/lib/arel_extensions/visitors/sqlite.rb +126 -140
- data/lib/arel_extensions/visitors/to_sql.rb +237 -298
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +31 -224
- data/test/database.yml +7 -15
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +117 -120
- data/test/support/fake_record.rb +3 -9
- data/test/test_comparators.rb +17 -14
- data/test/visitors/test_bulk_insert_oracle.rb +11 -11
- data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
- data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
- data/test/visitors/test_oracle.rb +55 -55
- data/test/visitors/test_to_sql.rb +226 -419
- data/test/with_ar/all_agnostic_test.rb +366 -711
- data/test/with_ar/insert_agnostic_test.rb +21 -27
- data/test/with_ar/test_bulk_sqlite.rb +16 -17
- data/test/with_ar/test_math_sqlite.rb +26 -26
- data/test/with_ar/test_string_mysql.rb +33 -31
- data/test/with_ar/test_string_sqlite.rb +34 -30
- metadata +34 -43
- data/.github/workflows/publish.yml +0 -29
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -399
- data/CONTRIBUTING.md +0 -102
- data/NEWS.md +0 -89
- data/bin/build +0 -15
- data/bin/compose +0 -6
- data/bin/publish +0 -8
- data/dev/arelx.dockerfile +0 -44
- data/dev/compose.yaml +0 -71
- data/dev/postgres.dockerfile +0 -5
- data/dev/rbenv +0 -189
- data/gemfiles/rails4_2.gemfile +0 -38
- data/gemfiles/rails5.gemfile +0 -29
- data/gemfiles/rails6.gemfile +0 -33
- data/gemfiles/rails6_1.gemfile +0 -33
- data/gemfiles/rails7.gemfile +0 -33
- data/gemfiles/rails7_1.gemfile +0 -33
- data/gemfiles/rails7_2.gemfile +0 -33
- data/gemspecs/arel_extensions-v1.gemspec +0 -27
- data/gemspecs/arel_extensions-v2.gemspec +0 -27
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/helpers.rb +0 -62
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
- data/lib/arel_extensions/nodes/rollup.rb +0 -36
- data/lib/arel_extensions/nodes/select.rb +0 -10
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/test/arelx_test_helper.rb +0 -74
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
data/README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# Arel Extensions
|
2
2
|
|
3
|
-
![
|
4
|
-
[![AppVeyor Build Status](https://img.shields.io/appveyor/ci/
|
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 (
|
12
|
-
It aims to ensure pure
|
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
|
-
|
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 '
|
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
|
-
|
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
|
-
|
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
128
|
|
152
|
-
```ruby
|
153
|
-
# datetime difference
|
154
|
-
t[:birthdate] - Time.utc(2014, 3, 3, 12, 41, 18)
|
155
|
-
|
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
|
-
|
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 'UTC' 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
|
-
-
|
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
|
-
```
|
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 +
|
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,19 +218,10 @@ 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 +
|
307
|
-
<td class="ok">✔</td>
|
308
|
-
<td class="ok">✔</td>
|
309
|
-
<td class="ok">✔</td>
|
310
|
-
</tr>
|
311
|
-
<tr>
|
312
|
-
<td class="tg-yw4l">POSIX FORMATTING<br>column.format_number("$ %7.2f","en_US")</td>
|
221
|
+
<td class="tg-j6lv">CASE + ROUND</td>
|
313
222
|
<td class="ok">✔</td>
|
314
223
|
<td class="ok">✔</td>
|
315
224
|
<td class="ok">✔</td>
|
316
|
-
<td class="ok">✔</td>
|
317
|
-
<td class="ok">✔</td>
|
318
|
-
<td class="ko">not implemented</td>
|
319
225
|
</tr>
|
320
226
|
<tr>
|
321
227
|
<td class="tg-yw4l">RAND<br>Arel.rand</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
|
-
<
|
349
|
-
<td class="
|
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
|
-
<
|
359
|
-
<td class="
|
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
|
-
|
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">
|
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"
|
418
|
-
<td class="tg-j6lv"
|
419
|
-
|
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">
|
300
|
+
<td class="tg-yw4l">FIND_IN_SET<br>column & ("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
|
-
|
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">
|
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(
|
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">
|
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">
|
476
|
-
<td class="
|
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="
|
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,14 +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>
|
data/Rakefile
CHANGED
@@ -1,57 +1,39 @@
|
|
1
1
|
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks name
|
2
|
+
Bundler::GemHelper.install_tasks :name => "arel_extensions"
|
3
3
|
|
4
4
|
require 'rake/testtask'
|
5
5
|
|
6
|
-
desc
|
7
|
-
task default: [:test]
|
6
|
+
desc "Default Task"
|
7
|
+
task default: [ :test ]
|
8
8
|
|
9
9
|
Rake::TestTask.new(:test) do |t|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|