arel_extensions 2.0.1 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -4
  3. data/.travis.yml +10 -10
  4. data/Gemfile +14 -19
  5. data/README.md +17 -12
  6. data/Rakefile +23 -23
  7. data/appveyor.yml +1 -1
  8. data/arel_extensions.gemspec +2 -2
  9. data/functions.html +3 -3
  10. data/gemfiles/rails6.gemfile +30 -0
  11. data/gemspec_v2/arel_extensions-v2.gemspec +28 -0
  12. data/generate_gems.sh +13 -0
  13. data/init/mssql.sql +4 -4
  14. data/init/mysql.sql +38 -38
  15. data/init/postgresql.sql +21 -21
  16. data/lib/arel_extensions/boolean_functions.rb +0 -2
  17. data/lib/arel_extensions/common_sql_functions.rb +5 -4
  18. data/lib/arel_extensions/comparators.rb +4 -2
  19. data/lib/arel_extensions/insert_manager.rb +12 -12
  20. data/lib/arel_extensions/math.rb +3 -3
  21. data/lib/arel_extensions/math_functions.rb +10 -5
  22. data/lib/arel_extensions/nodes/aggregate_function.rb +14 -0
  23. data/lib/arel_extensions/nodes/case.rb +0 -2
  24. data/lib/arel_extensions/nodes/coalesce.rb +2 -2
  25. data/lib/arel_extensions/nodes/collate.rb +1 -1
  26. data/lib/arel_extensions/nodes/concat.rb +6 -13
  27. data/lib/arel_extensions/nodes/date_diff.rb +3 -5
  28. data/lib/arel_extensions/nodes/duration.rb +0 -2
  29. data/lib/arel_extensions/nodes/format.rb +8 -8
  30. data/lib/arel_extensions/nodes/formatted_number.rb +23 -23
  31. data/lib/arel_extensions/nodes/function.rb +2 -0
  32. data/lib/arel_extensions/nodes/json.rb +28 -30
  33. data/lib/arel_extensions/nodes/matches.rb +4 -4
  34. data/lib/arel_extensions/nodes/power.rb +6 -5
  35. data/lib/arel_extensions/nodes/repeat.rb +2 -2
  36. data/lib/arel_extensions/nodes/replace.rb +24 -6
  37. data/lib/arel_extensions/nodes/round.rb +5 -5
  38. data/lib/arel_extensions/nodes/soundex.rb +16 -15
  39. data/lib/arel_extensions/nodes/std.rb +19 -21
  40. data/lib/arel_extensions/nodes/substring.rb +8 -15
  41. data/lib/arel_extensions/nodes/sum.rb +7 -0
  42. data/lib/arel_extensions/nodes/trim.rb +3 -3
  43. data/lib/arel_extensions/nodes/union.rb +2 -3
  44. data/lib/arel_extensions/nodes/union_all.rb +0 -1
  45. data/lib/arel_extensions/nodes.rb +1 -1
  46. data/lib/arel_extensions/null_functions.rb +2 -2
  47. data/lib/arel_extensions/predications.rb +16 -17
  48. data/lib/arel_extensions/string_functions.rb +21 -12
  49. data/lib/arel_extensions/tasks.rb +5 -5
  50. data/lib/arel_extensions/version.rb +1 -1
  51. data/lib/arel_extensions/visitors/mssql.rb +14 -13
  52. data/lib/arel_extensions/visitors/mysql.rb +72 -37
  53. data/lib/arel_extensions/visitors/oracle.rb +12 -11
  54. data/lib/arel_extensions/visitors/oracle12.rb +1 -1
  55. data/lib/arel_extensions/visitors/postgresql.rb +77 -31
  56. data/lib/arel_extensions/visitors/sqlite.rb +54 -40
  57. data/lib/arel_extensions/visitors/to_sql.rb +50 -31
  58. data/lib/arel_extensions.rb +20 -1
  59. data/test/helper.rb +1 -1
  60. data/test/real_db_test.rb +1 -1
  61. data/test/support/fake_record.rb +0 -4
  62. data/test/test_comparators.rb +1 -1
  63. data/test/visitors/test_bulk_insert_oracle.rb +6 -6
  64. data/test/visitors/test_bulk_insert_sqlite.rb +6 -6
  65. data/test/visitors/test_bulk_insert_to_sql.rb +7 -9
  66. data/test/visitors/test_oracle.rb +1 -0
  67. data/test/visitors/test_to_sql.rb +15 -1
  68. data/test/with_ar/all_agnostic_test.rb +54 -32
  69. data/test/with_ar/insert_agnostic_test.rb +2 -1
  70. data/test/with_ar/test_bulk_sqlite.rb +2 -2
  71. data/test/with_ar/test_math_sqlite.rb +3 -3
  72. data/test/with_ar/test_string_mysql.rb +3 -5
  73. data/test/with_ar/test_string_sqlite.rb +2 -6
  74. data/version_v1.rb +3 -0
  75. data/version_v2.rb +3 -0
  76. metadata +13 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6fcaaa3eed836e24e7838198a33d805aa3a344fdf773435bdee7035a06dede8
4
- data.tar.gz: b56147c3b2b87d0e69ce413e40ca0e4b1c35a2ff9d6183d46d2f808ef1584aaa
3
+ metadata.gz: 808040009223c9a359d5e61e55f84a51dad939ee8b388ec04e52cfd6554f0ef9
4
+ data.tar.gz: 836a734a724fd5328a66483d8d433a93eef9cbbaf78cf5e4ea10877c283c9ddc
5
5
  SHA512:
6
- metadata.gz: a614bd78ccd04e2f70175e30abd2857dd6edd4a4cdb1b530ef83d274de8a406d9320b8f6b0a6b6f9c537407326b1147780366ea36137d23b52d6c28961f3cd2f
7
- data.tar.gz: 22b0f75d7df193228edc5f4e071bde066ff5232eadaf34d06dfa48c5b23b07122dae0cc6d280c03ed8c4ec1c61fdde69df3efcdf0398f6a0fb00af28d1264e67
6
+ metadata.gz: eb328d50ea6213bf785f0a03ebb1b23494fb66e8c60bf7a8873ffc84f3d78e5f9d2ec57367b7a5475872a899134edf5332e2b8dfe90128d22a7fe650e95c4f95
7
+ data.tar.gz: e9098b71c1fdb119c5a3e6a18409ce3096487eb8a5adffc827dde03fbf65139d37fe1bef525c4b261a1ddfbfb3cfa4f0ca079152519c6f3c5813975b5a9b3c5b
data/.rubocop.yml CHANGED
@@ -12,7 +12,10 @@ Layout/ExtraSpacing:
12
12
  Layout/SpaceAroundEqualsInParameterDefault:
13
13
  Enabled: true
14
14
 
15
- Layout/TrailingBlankLines:
15
+ Layout/TrailingEmptyLines:
16
+ Enabled: true
17
+
18
+ Naming/FileName:
16
19
  Enabled: true
17
20
 
18
21
  Style/CollectionMethods:
@@ -33,12 +36,12 @@ Style/EmptyElse:
33
36
  Style/Encoding:
34
37
  Enabled: true
35
38
 
36
- Style/FileName:
37
- Enabled: true
38
-
39
39
  Style/MethodCallWithArgsParentheses:
40
40
  Enabled: false
41
41
 
42
+ # Performance cops have been transferred to rubocop-performance gem.
43
+ require: rubocop-performance
44
+
42
45
  Performance/DoubleStartEndWith:
43
46
  Enabled: true
44
47
 
data/.travis.yml CHANGED
@@ -86,7 +86,7 @@ matrix:
86
86
  - rvm: 2.5.0
87
87
  jdk: openjdk7
88
88
  - rvm: ruby-head
89
- jdk: openjdk7
89
+ jdk: openjdk7
90
90
  - rvm: rbx-2
91
91
  jdk: oraclejdk8
92
92
  - rvm: 2.0.0
@@ -150,7 +150,7 @@ matrix:
150
150
  - rvm: 2.5.0
151
151
  jdk: oraclejdk11
152
152
  - rvm: ruby-head
153
- jdk: oraclejdk11
153
+ jdk: oraclejdk11
154
154
  - rvm: rbx-2
155
155
  jdk: openjdk11
156
156
  - rvm: 2.0.0
@@ -166,7 +166,7 @@ matrix:
166
166
  - rvm: 2.5.0
167
167
  jdk: openjdk11
168
168
  - rvm: ruby-head
169
- jdk: openjdk11
169
+ jdk: openjdk11
170
170
  - rvm: jruby-9.2.0.0
171
171
  jdk: openjdk7
172
172
  - rvm: jruby-head
@@ -182,7 +182,7 @@ matrix:
182
182
  - rvm: 2.0.0
183
183
  gemfile: gemfiles/rails5_0.gemfile
184
184
  - rvm: 2.1
185
- gemfile: gemfiles/rails5_0.gemfile
185
+ gemfile: gemfiles/rails5_0.gemfile
186
186
  - rvm: jruby-9.0.5.0
187
187
  gemfile: gemfiles/rails5_1_4.gemfile
188
188
  - rvm: 2.0.0
@@ -191,17 +191,17 @@ matrix:
191
191
  gemfile: gemfiles/rails5_2.gemfile
192
192
  allow_failures:
193
193
  - rvm: rbx-2
194
- gemfile: gemfiles/rails4.gemfile
194
+ gemfile: gemfiles/rails4.gemfile
195
195
  - rvm: rbx-2
196
- gemfile: gemfiles/rails5_0.gemfile
196
+ gemfile: gemfiles/rails5_0.gemfile
197
197
  - rvm: rbx-2
198
- gemfile: gemfiles/rails5_1_4.gemfile
198
+ gemfile: gemfiles/rails5_1_4.gemfile
199
199
  - rvm: rbx-2
200
200
  gemfile: gemfiles/rails5_2.gemfile
201
201
  - rvm: rbx-2
202
202
  gemfile: gemfiles/rails5_1_4.gemfile
203
- - rvm: jruby-9.0.5.0
204
- gemfile: gemfiles/rails5_2.gemfile
203
+ - rvm: jruby-9.0.5.0
204
+ gemfile: gemfiles/rails5_2.gemfile
205
205
  - rvm: jruby-9.2.0.0
206
206
  jdk: oraclejdk9
207
207
  gemfile: gemfiles/rails5_2.gemfile
@@ -217,7 +217,7 @@ matrix:
217
217
  jdk: oraclejdk9
218
218
  bundler_args: "--jobs 3 --retry 2"
219
219
  notifications:
220
- email:
220
+ email:
221
221
  notifications:
222
222
  - julien.delporte@faveod.com
223
223
  - yann.azoury@faveod.com
data/Gemfile CHANGED
@@ -1,29 +1,24 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rails', '~> 6.0.0.rc2'
4
-
3
+ gemspec
5
4
 
6
5
  group :development, :test do
7
- gem 'activesupport', '~> 6.0.0.rc2'
8
- gem 'activemodel', '~> 6.0.0.rc2'
9
- gem 'activerecord', '~> 6.0.0.rc2'
10
-
11
- gem "sqlite3", '~> 1.4', :platforms => [:mri, :mswin, :mingw]
12
- gem "mysql2", '0.5.2', :platforms => [:mri, :mswin, :mingw]
13
- gem "pg",'< 1.0.0', :platforms => [:mri, :mingw]
14
-
15
- gem "tiny_tds", :platforms => [:mri, :mingw] if RUBY_PLATFORM =~ /windows/
16
- gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
17
-
18
- gem 'ruby-oci8', :platforms => [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
19
- gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0.rc2' if ENV.has_key? 'ORACLE_HOME'
6
+ gem "sqlite3", '<= 1.3.13', :platforms => [:mri, :mswin, :x64_mingw, :mingw]
7
+ gem "mysql2", '0.4.10', :platforms => [:mri, :mswin, :x64_mingw, :mingw]
8
+ gem "pg", '< 1', :platforms => [:mri, :mingw, :x64_mingw, :mswin]
20
9
 
21
- # for JRuby
22
- gem 'activerecord-jdbc-adapter', :platforms => :jruby
23
10
  gem "jdbc-sqlite3", :platforms => :jruby
24
11
  gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
25
12
  gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
26
13
  gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
27
- gem "activerecord-jdbcmssql-adapter", :platforms => :jruby
28
- end
29
14
 
15
+ gem "tiny_tds", '~> 1.3.0' ,:require => false, :platforms => [:mri,:mingw, :x64_mingw, :mswin]
16
+ gem "activerecord-sqlserver-adapter", '~> 4.2.0', :platforms => [:mri, :mingw, :x64_mingw, :mswin]
17
+
18
+ gem 'ruby-oci8', :platforms => [:mri, :mswin, :x64_mingw, :mingw]
19
+ gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
20
+
21
+ gem 'activesupport', '~> 4.0'
22
+ gem 'activemodel', '~> 4.0'
23
+ gem 'activerecord', '~> 4.0'
24
+ end
data/README.md CHANGED
@@ -19,6 +19,11 @@ It allows to use more advanced SQL functions for any supported RDBMS.
19
19
  Arel 6 (Rails 4) or Arel 7+ (Rails 5).
20
20
  [Arel Repository](http://github.com/rails/arel)
21
21
 
22
+ or
23
+
24
+ Rails 6
25
+ [Arel Repository](http://github.com/rails/rails)
26
+
22
27
  ## Usage
23
28
 
24
29
  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:
@@ -72,9 +77,9 @@ With Arel Extensions:
72
77
  Other functions : ABS, RAND, ROUND, FLOOR, CEIL, FORMAT
73
78
 
74
79
  For Example:
75
- ```ruby
80
+ ```ruby
76
81
  t[:price].format_number("%07.2f €","fr_FR")
77
- # equivalent to 'sprintf("%07.2f €",price)' plus locale management
82
+ # equivalent to 'sprintf("%07.2f €",price)' plus locale management
78
83
  ```
79
84
 
80
85
  ## String operations
@@ -130,7 +135,7 @@ t[:birthdate].format('%Y-%m-%d').to_sql
130
135
  # => DATE_FORMAT(my_table.birthdate, '%Y-%m-%d')
131
136
  ```
132
137
 
133
- ## Unions
138
+ ## Unions
134
139
 
135
140
  ```ruby
136
141
  (t.where(t[:name].eq('str')) + t.where(t[:name].eq('test'))).to_sql
@@ -143,7 +148,7 @@ Arel-extensions allows to use functions on case clause
143
148
 
144
149
  ```ruby
145
150
  t[:name].when("smith").then(1).when("doe").then(2).else(0).sum.to_sql
146
- # => SUM(CASE "my_table"."name" WHEN 'smith' THEN 1 WHEN 'doe' THEN 2 ELSE 0 END)
151
+ # => SUM(CASE "my_table"."name" WHEN 'smith' THEN 1 WHEN 'doe' THEN 2 ELSE 0 END)
147
152
  ```
148
153
 
149
154
  ## Cast Function
@@ -160,7 +165,7 @@ t[:id].cast('char').to_sql
160
165
 
161
166
  To optimize queries, some classical functions are defined in databases missing any alternative native functions.
162
167
  Examples :
163
- - FIND_IN_SET
168
+ - FIND_IN_SET
164
169
 
165
170
  ## BULK INSERT / UPSERT
166
171
 
@@ -209,7 +214,7 @@ User.connection.execute(insert_manager.to_sql)
209
214
  <td class="tg-yw4l">CEIL<br>column.ceil</td>
210
215
  <td class="ok">✔</td>
211
216
  <td class="ok">✔</td>
212
- <td class="tg-j6lv">CASE + ROUND</td>
217
+ <td class="tg-j6lv">CASE + CAST</td>
213
218
  <td class="ok">✔</td>
214
219
  <td class="tg-j6lv">CEILING()</td>
215
220
  <td class="tg-j6lv">CEILING()</td>
@@ -218,7 +223,7 @@ User.connection.execute(insert_manager.to_sql)
218
223
  <td class="tg-yw4l">FLOOR<br>column.floor</td>
219
224
  <td class="ok">✔</td>
220
225
  <td class="ok">✔</td>
221
- <td class="tg-j6lv">CASE + ROUND</td>
226
+ <td class="tg-j6lv">CASE + CAST</td>
222
227
  <td class="ok">✔</td>
223
228
  <td class="ok">✔</td>
224
229
  <td class="ok">✔</td>
@@ -385,7 +390,7 @@ User.connection.execute(insert_manager.to_sql)
385
390
  <td class="ok">✔</td>
386
391
  <td class="tg-j6lv">✔</td>
387
392
  <td class="tg-j6lv">?</td>
388
- </tr>
393
+ </tr>
389
394
  <tr>
390
395
  <td class="tg-yw4l">Matching Accent Insensitive<br>column.ai_matches('blah')</td>
391
396
  <td class="ok">not supported</td>
@@ -394,7 +399,7 @@ User.connection.execute(insert_manager.to_sql)
394
399
  <td class="ok">not supported</td>
395
400
  <td class="tg-j6lv">✔</td>
396
401
  <td class="tg-j6lv">?</td>
397
- </tr>
402
+ </tr>
398
403
  <tr>
399
404
  <td class="tg-yw4l">Matching Case Insensitive<br>column.imatches('blah')</td>
400
405
  <td class="ok">not supported</td>
@@ -403,7 +408,7 @@ User.connection.execute(insert_manager.to_sql)
403
408
  <td class="ok">✔</td>
404
409
  <td class="tg-j6lv">✔</td>
405
410
  <td class="tg-j6lv">?</td>
406
- </tr>
411
+ </tr>
407
412
  <tr>
408
413
  <td class="tg-yw4l">Matching Accent/Case Sensitive<br>column.smatches('blah')</td>
409
414
  <td class="ok">✔</td>
@@ -412,8 +417,8 @@ User.connection.execute(insert_manager.to_sql)
412
417
  <td class="ok">✔</td>
413
418
  <td class="tg-j6lv">✔</td>
414
419
  <td class="tg-j6lv">?</td>
415
- </tr>
416
-
420
+ </tr>
421
+
417
422
  <tr>
418
423
  <th class="tg-4rp9" rowspan="6"><div>Date functions</div></th>
419
424
  <td class="tg-yw4l">DATEADD<br>column + 2.year<br></td>
data/Rakefile CHANGED
@@ -7,33 +7,33 @@ desc "Default Task"
7
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
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
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
28
 
29
- namespace adapter do
30
- task :test => "test_#{adapter}"
31
- task :isolated_test => "isolated_test_#{adapter}"
29
+ namespace adapter do
30
+ task :test => "test_#{adapter}"
31
+ task :isolated_test => "isolated_test_#{adapter}"
32
32
 
33
- # Set the connection environment for the adapter
34
- task(:env) { ENV['DB'] = adapter }
35
- end
33
+ # Set the connection environment for the adapter
34
+ task(:env) { ENV['DB'] = adapter }
35
+ end
36
36
 
37
- # Make sure the adapter test evaluates the env setting task
38
- task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
37
+ # Make sure the adapter test evaluates the env setting task
38
+ task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
39
39
  end
data/appveyor.yml CHANGED
@@ -41,4 +41,4 @@ environment:
41
41
  - RUBY_VERSION: 22
42
42
  - RUBY_VERSION: 23
43
43
  - RUBY_VERSION: 23-x64
44
-
44
+
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_dependency('activerecord', '>= 6.0.0')
23
+ s.add_dependency('arel', '>= 6.0')
24
24
 
25
25
  s.add_development_dependency('minitest', '~> 5.9')
26
26
  s.add_development_dependency('rdoc', '~> 4.0')
27
- s.add_development_dependency('rake', '~> 11')
27
+ s.add_development_dependency('rake', '~> 12.3.3')
28
28
  end
data/functions.html CHANGED
@@ -55,7 +55,7 @@
55
55
  <td class="tg-yw4l">CEIL<br>column.ceil</td>
56
56
  <td class="ok">✔</td>
57
57
  <td class="ok">✔</td>
58
- <td class="tg-j6lv">CASE + ROUND</td>
58
+ <td class="tg-j6lv">CASE + CAST</td>
59
59
  <td class="ok">✔</td>
60
60
  <td class="tg-j6lv">CEILING()</td>
61
61
  <td class="tg-j6lv">CEILING()</td>
@@ -64,7 +64,7 @@
64
64
  <td class="tg-yw4l">FLOOR<br>column.floor</td>
65
65
  <td class="ok">✔</td>
66
66
  <td class="ok">✔</td>
67
- <td class="tg-j6lv">CASE + ROUND</td>
67
+ <td class="tg-j6lv">CASE + CAST</td>
68
68
  <td class="ok">✔</td>
69
69
  <td class="ok">✔</td>
70
70
  <td class="ok">✔</td>
@@ -379,7 +379,7 @@
379
379
  <td class="ok">✔</td>
380
380
  <td class="ok">✔</td>
381
381
  <td class="ok">✔</td>
382
- </tr>
382
+ </tr>
383
383
  <tr>
384
384
  <th class="bulk_insert" rowspan="1"><div>Set<br/> Operators</div></th>
385
385
  <td class="tg-yw4l">UNION ( + )<br/>query + query</td>
@@ -0,0 +1,30 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rails', '~> 6.0.0'
4
+
5
+
6
+ group :development, :test do
7
+ gem 'activesupport', '~> 6.0.0'
8
+ gem 'activemodel', '~> 6.0.0'
9
+ gem 'activerecord', '~> 6.0.0'
10
+
11
+ gem "sqlite3", '~> 1.4', :platforms => [:mri, :mswin, :mingw]
12
+ gem "mysql2", '0.5.2', :platforms => [:mri, :mswin, :mingw]
13
+ gem "pg",'< 1.0.0', :platforms => [:mri, :mingw]
14
+
15
+ gem "tiny_tds", :platforms => [:mri, :mingw] if RUBY_PLATFORM =~ /windows/
16
+ gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
17
+
18
+ gem 'ruby-oci8', :platforms => [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
19
+ gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
20
+
21
+ # for JRuby
22
+ gem 'activerecord-jdbc-adapter', :platforms => :jruby
23
+ gem "jdbc-sqlite3", :platforms => :jruby
24
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
25
+ gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
26
+ gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
27
+ gem "activerecord-jdbcmssql-adapter", :platforms => :jruby
28
+ end
29
+
30
+ gemspec :path => "../"
@@ -0,0 +1,28 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "arel_extensions/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "arel_extensions"
6
+ s.version = ArelExtensions::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Yann Azoury", "Félix Bellanger", "Julien Delporte"]
9
+ s.email = ["yann.azoury@faveod.com", "felix.bellanger@faveod.com", "julien.delporte@faveod.com"]
10
+ s.homepage = "https://github.com/Faveod/arel-extensions"
11
+ s.description = "Adds new features to Arel"
12
+ s.summary = "Extending Arel"
13
+ s.license = 'MIT'
14
+
15
+ s.rdoc_options = ["--main", "README.md"]
16
+ s.extra_rdoc_files = ["MIT-LICENSE.txt", "README.md", 'functions.html']
17
+
18
+ # Manifest
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency('activerecord', '>= 6.0')
24
+
25
+ s.add_development_dependency('minitest', '~> 5.9')
26
+ s.add_development_dependency('rdoc', '~> 4.0')
27
+ s.add_development_dependency('rake', '~> 12.3.3')
28
+ end
data/generate_gems.sh ADDED
@@ -0,0 +1,13 @@
1
+
2
+ gem uninstall arel_extensions
3
+
4
+ # VERSION ~> 1
5
+ cp ./version_v1.rb lib/arel_extensions/version.rb
6
+ gem build ./arel_extensions.gemspec
7
+
8
+ # VERSION ~> 2
9
+ cp ./version_v2.rb lib/arel_extensions/version.rb
10
+ cp ./gemspec_v2/arel_extensions-v2.gemspec ./tmp.gemspec
11
+ gem build ./tmp.gemspec
12
+ cp ./version_v1.rb lib/arel_extensions/version.rb
13
+ rm tmp.gemspec
data/init/mssql.sql CHANGED
@@ -83,7 +83,7 @@ BEGIN
83
83
  END
84
84
  SELECT @cv1 = @cv0, @i = @i + 1
85
85
  END
86
- RETURN @c
86
+ RETURN @c
87
87
  END
88
88
  GO
89
89
 
@@ -94,9 +94,9 @@ GO
94
94
  --RETURNS TABLE
95
95
  --AS
96
96
  --BEGIN
97
- -- RETURN ( SELECT [Value] FROM
98
- -- (
99
- -- SELECT
97
+ -- RETURN ( SELECT [Value] FROM
98
+ -- (
99
+ -- SELECT
100
100
  -- [Value] = LTRIM(RTRIM(SUBSTRING(@List, [Number],
101
101
  -- CHARINDEX(@Delim, @List + @Delim, [Number]) - [Number])))
102
102
  -- FROM (SELECT Number = ROW_NUMBER() OVER (ORDER BY name)
data/init/mysql.sql CHANGED
@@ -1,45 +1,45 @@
1
1
  DELIMITER $$
2
2
 
3
3
  DROP FUNCTION IF EXISTS levenshtein_distance; $$
4
- CREATE FUNCTION levenshtein_distance( s1 VARCHAR(255), s2 VARCHAR(255) )
5
- RETURNS INT
6
- DETERMINISTIC
7
- BEGIN
8
- DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT;
9
- DECLARE s1_char CHAR;
10
- -- max strlen=255
11
- DECLARE cv0, cv1 VARBINARY(256);
4
+ CREATE FUNCTION levenshtein_distance( s1 VARCHAR(255), s2 VARCHAR(255) )
5
+ RETURNS INT
6
+ DETERMINISTIC
7
+ BEGIN
8
+ DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT;
9
+ DECLARE s1_char CHAR;
10
+ -- max strlen=255
11
+ DECLARE cv0, cv1 VARBINARY(256);
12
12
  SET s1 = IFNULL(s1,''), s2 = IFNULL(s2,'');
13
- SET s1_len = CHAR_LENGTH(IFNULL(s1,'')), s2_len = CHAR_LENGTH(IFNULL(s2,'')), cv1 = 0x00, j = 1, i = 1, c = 0;
14
- IF s1_len = 0 THEN
15
- RETURN s2_len;
16
- ELSEIF s2_len = 0 THEN
17
- RETURN s1_len;
18
- ELSEIF s1 = s2 THEN
13
+ SET s1_len = CHAR_LENGTH(IFNULL(s1,'')), s2_len = CHAR_LENGTH(IFNULL(s2,'')), cv1 = 0x00, j = 1, i = 1, c = 0;
14
+ IF s1_len = 0 THEN
15
+ RETURN s2_len;
16
+ ELSEIF s2_len = 0 THEN
17
+ RETURN s1_len;
18
+ ELSEIF s1 = s2 THEN
19
19
  RETURN 0;
20
- ELSE
21
- WHILE j <= s2_len DO
22
- SET cv1 = CONCAT(cv1, UNHEX(HEX(j))), j = j + 1;
23
- END WHILE;
24
- WHILE i <= s1_len DO
25
- SET s1_char = SUBSTRING(s1, i, 1), c = i, cv0 = UNHEX(HEX(i)), j = 1;
26
- WHILE j <= s2_len DO
27
- SET c = c + 1;
28
- IF s1_char = SUBSTRING(s2, j, 1) THEN
29
- SET cost = 0; ELSE SET cost = 1;
30
- END IF;
31
- SET c_temp = CONV(HEX(SUBSTRING(cv1, j, 1)), 16, 10) + cost;
32
- IF c > c_temp THEN SET c = c_temp; END IF;
33
- SET c_temp = CONV(HEX(SUBSTRING(cv1, j+1, 1)), 16, 10) + 1;
34
- IF c > c_temp THEN
35
- SET c = c_temp;
36
- END IF;
37
- SET cv0 = CONCAT(cv0, UNHEX(HEX(c))), j = j + 1;
38
- END WHILE;
39
- SET cv1 = cv0, i = i + 1;
40
- END WHILE;
41
- END IF;
42
- RETURN c;
20
+ ELSE
21
+ WHILE j <= s2_len DO
22
+ SET cv1 = CONCAT(cv1, UNHEX(HEX(j))), j = j + 1;
23
+ END WHILE;
24
+ WHILE i <= s1_len DO
25
+ SET s1_char = SUBSTRING(s1, i, 1), c = i, cv0 = UNHEX(HEX(i)), j = 1;
26
+ WHILE j <= s2_len DO
27
+ SET c = c + 1;
28
+ IF s1_char = SUBSTRING(s2, j, 1) THEN
29
+ SET cost = 0; ELSE SET cost = 1;
30
+ END IF;
31
+ SET c_temp = CONV(HEX(SUBSTRING(cv1, j, 1)), 16, 10) + cost;
32
+ IF c > c_temp THEN SET c = c_temp; END IF;
33
+ SET c_temp = CONV(HEX(SUBSTRING(cv1, j+1, 1)), 16, 10) + 1;
34
+ IF c > c_temp THEN
35
+ SET c = c_temp;
36
+ END IF;
37
+ SET cv0 = CONCAT(cv0, UNHEX(HEX(c))), j = j + 1;
38
+ END WHILE;
39
+ SET cv1 = cv0, i = i + 1;
40
+ END WHILE;
41
+ END IF;
42
+ RETURN c;
43
43
  END;$$
44
-
44
+
45
45
  DELIMITER ;
data/init/postgresql.sql CHANGED
@@ -4,17 +4,17 @@ CREATE OR REPLACE FUNCTION public.find_in_set(n INTEGER, s TEXT)
4
4
  AS $function$
5
5
  SELECT * FROM (
6
6
  select int4(z.row_number) from (
7
- select row_number() over(), y.x
7
+ select row_number() over(), y.x
8
8
  from (select unnest(('{' || $2 || '}')::int[]) as x) as y
9
9
  ) as z
10
10
  where z.x = $1
11
- UNION ALL
11
+ UNION ALL
12
12
  SELECT 0) z
13
13
  LIMIT 1
14
14
  $function$
15
15
  ;
16
16
 
17
- CREATE OR REPLACE FUNCTION public.levenshtein_distance(s text, t text)
17
+ CREATE OR REPLACE FUNCTION public.levenshtein_distance(s text, t text)
18
18
  RETURNS integer AS $$
19
19
  DECLARE i integer;
20
20
  DECLARE j integer;
@@ -48,58 +48,58 @@ BEGIN
48
48
  d[i*(n+1)+j] := LEAST(d[(i-1)*(n+1)+j]+1, d[i*(n+1)+j-1]+1, d[(i-1)*(n+1)+j-1]+c);
49
49
  END LOOP;
50
50
  END LOOP;
51
-
52
- return d[m*(n+1)+n];
51
+
52
+ return d[m*(n+1)+n];
53
53
  END;
54
54
  $$ LANGUAGE plpgsql IMMUTABLE;
55
55
 
56
- CREATE OR REPLACE FUNCTION public.DateDiff(units VARCHAR(30), start_t TIMESTAMP, end_t TIMESTAMP)
56
+ CREATE OR REPLACE FUNCTION public.DateDiff(units VARCHAR(30), start_t TIMESTAMP, end_t TIMESTAMP)
57
57
  RETURNS INT AS $$
58
58
  DECLARE
59
- diff_interval INTERVAL;
59
+ diff_interval INTERVAL;
60
60
  diff INT = 0;
61
61
  years_diff INT = 0;
62
62
  BEGIN
63
63
  IF units IN ('yy', 'yyyy', 'year', 'mm', 'm', 'month') THEN
64
64
  years_diff = DATE_PART('year', end_t) - DATE_PART('year', start_t);
65
-
65
+
66
66
  IF units IN ('yy', 'yyyy', 'year') THEN
67
67
  -- SQL Server does not count full years passed (only difference between year parts)
68
68
  RETURN years_diff;
69
69
  ELSE
70
70
  -- If end month is less than start month it will subtracted
71
- RETURN years_diff * 12 + (DATE_PART('month', end_t) - DATE_PART('month', start_t));
71
+ RETURN years_diff * 12 + (DATE_PART('month', end_t) - DATE_PART('month', start_t));
72
72
  END IF;
73
73
  END IF;
74
-
75
- -- Minus operator returns interval 'DDD days HH:MI:SS'
74
+
75
+ -- Minus operator returns interval 'DDD days HH:MI:SS'
76
76
  diff_interval = end_t - start_t;
77
-
77
+
78
78
  diff = diff + DATE_PART('day', diff_interval);
79
-
79
+
80
80
  IF units IN ('wk', 'ww', 'week') THEN
81
81
  diff = diff/7;
82
82
  RETURN diff;
83
83
  END IF;
84
-
84
+
85
85
  IF units IN ('dd', 'd', 'day') THEN
86
86
  RETURN diff;
87
87
  END IF;
88
-
89
- diff = diff * 24 + DATE_PART('hour', diff_interval);
90
-
88
+
89
+ diff = diff * 24 + DATE_PART('hour', diff_interval);
90
+
91
91
  IF units IN ('hh', 'hour') THEN
92
92
  RETURN diff;
93
93
  END IF;
94
-
94
+
95
95
  diff = diff * 60 + DATE_PART('minute', diff_interval);
96
-
96
+
97
97
  IF units IN ('mi', 'n', 'minute') THEN
98
98
  RETURN diff;
99
99
  END IF;
100
-
100
+
101
101
  diff = diff * 60 + DATE_PART('second', diff_interval);
102
-
102
+
103
103
  RETURN diff;
104
104
  END;
105
105
  $$ LANGUAGE plpgsql;
@@ -41,5 +41,3 @@ end
41
41
  ArelExtensions::Nodes.const_set('Or',Class.new(Arel::Nodes::And)).class_eval do
42
42
  include ArelExtensions::BooleanFunctions
43
43
  end
44
-
45
-