arel_extensions 1.2.25 → 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/.rubocop.yml +4 -7
- data/.travis.yml +91 -61
- data/Gemfile +20 -15
- data/README.md +12 -17
- data/Rakefile +29 -40
- data/appveyor.yml +1 -1
- data/arel_extensions.gemspec +3 -3
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +9 -9
- data/gemfiles/rails4.gemfile +13 -13
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +13 -13
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/postgresql.sql +21 -21
- data/lib/arel_extensions/attributes.rb +1 -0
- data/lib/arel_extensions/boolean_functions.rb +14 -55
- data/lib/arel_extensions/common_sql_functions.rb +8 -7
- data/lib/arel_extensions/comparators.rb +15 -14
- data/lib/arel_extensions/date_duration.rb +5 -4
- data/lib/arel_extensions/insert_manager.rb +16 -17
- data/lib/arel_extensions/math.rb +12 -11
- data/lib/arel_extensions/math_functions.rb +22 -29
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +1 -0
- data/lib/arel_extensions/nodes/case.rb +8 -11
- data/lib/arel_extensions/nodes/cast.rb +2 -4
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +3 -2
- data/lib/arel_extensions/nodes/collate.rb +2 -1
- data/lib/arel_extensions/nodes/concat.rb +16 -7
- data/lib/arel_extensions/nodes/date_diff.rb +13 -10
- 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 -34
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +16 -25
- data/lib/arel_extensions/nodes/json.rb +36 -43
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +1 -0
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +6 -4
- 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 +4 -2
- data/lib/arel_extensions/nodes/replace.rb +6 -22
- 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 +0 -0
- data/lib/arel_extensions/nodes/trim.rb +5 -3
- data/lib/arel_extensions/nodes/union.rb +5 -2
- data/lib/arel_extensions/nodes/union_all.rb +3 -0
- data/lib/arel_extensions/nodes/wday.rb +4 -0
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +7 -5
- data/lib/arel_extensions/predications.rb +34 -35
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +4 -2
- data/lib/arel_extensions/string_functions.rb +23 -52
- data/lib/arel_extensions/tasks.rb +5 -5
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +12 -5
- data/lib/arel_extensions/visitors/mssql.rb +58 -64
- data/lib/arel_extensions/visitors/mysql.rb +98 -149
- data/lib/arel_extensions/visitors/oracle.rb +70 -73
- data/lib/arel_extensions/visitors/oracle12.rb +15 -2
- data/lib/arel_extensions/visitors/postgresql.rb +63 -116
- data/lib/arel_extensions/visitors/sqlite.rb +70 -83
- data/lib/arel_extensions/visitors/to_sql.rb +110 -142
- data/lib/arel_extensions/visitors.rb +60 -68
- data/lib/arel_extensions.rb +19 -81
- data/test/database.yml +0 -2
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +43 -28
- data/test/support/fake_record.rb +2 -2
- data/test/test_comparators.rb +12 -9
- data/test/visitors/test_bulk_insert_oracle.rb +8 -8
- data/test/visitors/test_bulk_insert_sqlite.rb +10 -9
- data/test/visitors/test_bulk_insert_to_sql.rb +10 -8
- data/test/visitors/test_oracle.rb +42 -42
- data/test/visitors/test_to_sql.rb +196 -361
- data/test/with_ar/all_agnostic_test.rb +160 -195
- data/test/with_ar/insert_agnostic_test.rb +4 -3
- data/test/with_ar/test_bulk_sqlite.rb +9 -6
- data/test/with_ar/test_math_sqlite.rb +12 -8
- data/test/with_ar/test_string_mysql.rb +11 -5
- data/test/with_ar/test_string_sqlite.rb +12 -4
- metadata +11 -22
- data/.github/workflows/ruby.yml +0 -102
- data/gemfiles/rails6.gemfile +0 -30
- data/gemfiles/rails6_1.gemfile +0 -30
- data/gemspecs/arel_extensions-v1.gemspec +0 -28
- data/gemspecs/arel_extensions-v2.gemspec +0 -28
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- 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 -26
- data/version_v1.rb +0 -3
- data/version_v2.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66c2dbd555cb0f702ba816dfd15143d1206667a52d3e9ef531837cede739ce1b
|
4
|
+
data.tar.gz: 7bddb377ad0a827d95a9b1a6d0dbedf2a60edcacb65a7ca485b341dedeced96b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28b4685b962e6e2d608ed3e0a482a9ee2af533d8529438223caed947e07dbc286238c510b897b0c090e4abcb968261cc660a42929a909ddd21950c375669b2df
|
7
|
+
data.tar.gz: 5cd46969679f69c1dcc67c18c8f184c17f14f269e6e4de1e4ebd1c048a0e8844d9d25ef9c44c359534346f1b9439b1ee24b08497f434f8bf9bab07d461ca2a33
|
data/.rubocop.yml
CHANGED
@@ -12,10 +12,7 @@ Layout/ExtraSpacing:
|
|
12
12
|
Layout/SpaceAroundEqualsInParameterDefault:
|
13
13
|
Enabled: true
|
14
14
|
|
15
|
-
Layout/
|
16
|
-
Enabled: true
|
17
|
-
|
18
|
-
Naming/FileName:
|
15
|
+
Layout/TrailingBlankLines:
|
19
16
|
Enabled: true
|
20
17
|
|
21
18
|
Style/CollectionMethods:
|
@@ -36,12 +33,12 @@ Style/EmptyElse:
|
|
36
33
|
Style/Encoding:
|
37
34
|
Enabled: true
|
38
35
|
|
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
|
-
|
45
42
|
Performance/DoubleStartEndWith:
|
46
43
|
Enabled: true
|
47
44
|
|
data/.travis.yml
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: required
|
3
|
-
dist: trusty
|
4
3
|
cache:
|
5
4
|
bundler: true
|
6
5
|
directories:
|
@@ -16,23 +15,21 @@ before_install:
|
|
16
15
|
# - sh -ex .travis/oracle/install.sh
|
17
16
|
# - .travis/setup_accounts.sh
|
18
17
|
install:
|
18
|
+
- gem install bundler -v 1.17.3
|
19
19
|
- bundle install
|
20
20
|
gemfile:
|
21
21
|
- gemfiles/rails4.gemfile
|
22
22
|
- gemfiles/rails5_0.gemfile
|
23
23
|
- gemfiles/rails5_1_4.gemfile
|
24
24
|
- gemfiles/rails5_2.gemfile
|
25
|
-
- gemfiles/rails6.gemfile
|
26
25
|
services:
|
27
26
|
- mysql
|
28
27
|
- postgresql
|
29
|
-
addons:
|
30
|
-
postgresql: '9.4'
|
31
28
|
before_script:
|
32
29
|
- mysql -e 'create database arext_test;'
|
33
30
|
- psql -c 'create database arext_test;' -U postgres
|
34
31
|
script:
|
35
|
-
-
|
32
|
+
- gem build arel_extensions.gemspec
|
36
33
|
- bundle exec rake test
|
37
34
|
- bundle exec rake test:sqlite
|
38
35
|
- bundle exec rake test:mysql
|
@@ -58,33 +55,72 @@ rvm:
|
|
58
55
|
- 2.3.1
|
59
56
|
- 2.4.0
|
60
57
|
- 2.5.0
|
61
|
-
- 2
|
58
|
+
- rbx-2
|
62
59
|
- jruby-9.0.5.0
|
63
|
-
- jruby-9.2.
|
60
|
+
- jruby-9.2.0.0
|
64
61
|
- jruby-head
|
62
|
+
- ruby-head
|
65
63
|
jdk:
|
64
|
+
- openjdk7
|
66
65
|
- oraclejdk8
|
67
66
|
- oraclejdk9
|
68
67
|
- openjdk10
|
68
|
+
- oraclejdk10
|
69
69
|
- openjdk11
|
70
70
|
- oraclejdk11
|
71
71
|
matrix:
|
72
72
|
fast_finish: true
|
73
73
|
exclude:
|
74
|
+
- rvm: rbx-2
|
75
|
+
jdk: openjdk7
|
74
76
|
- rvm: 2.0.0
|
75
|
-
jdk:
|
77
|
+
jdk: openjdk7
|
76
78
|
- rvm: 2.1
|
77
|
-
jdk:
|
79
|
+
jdk: openjdk7
|
78
80
|
- rvm: 2.2.5
|
79
|
-
jdk:
|
81
|
+
jdk: openjdk7
|
80
82
|
- rvm: 2.3.1
|
81
|
-
jdk:
|
83
|
+
jdk: openjdk7
|
82
84
|
- rvm: 2.4.0
|
83
|
-
jdk:
|
85
|
+
jdk: openjdk7
|
84
86
|
- rvm: 2.5.0
|
85
|
-
jdk:
|
86
|
-
- rvm:
|
87
|
-
jdk:
|
87
|
+
jdk: openjdk7
|
88
|
+
- rvm: ruby-head
|
89
|
+
jdk: openjdk7
|
90
|
+
- rvm: rbx-2
|
91
|
+
jdk: oraclejdk8
|
92
|
+
- rvm: 2.0.0
|
93
|
+
jdk: oraclejdk8
|
94
|
+
- rvm: 2.1
|
95
|
+
jdk: oraclejdk8
|
96
|
+
- rvm: 2.2.5
|
97
|
+
jdk: oraclejdk8
|
98
|
+
- rvm: 2.3.1
|
99
|
+
jdk: oraclejdk8
|
100
|
+
- rvm: 2.4.0
|
101
|
+
jdk: oraclejdk8
|
102
|
+
- rvm: 2.5.0
|
103
|
+
jdk: oraclejdk8
|
104
|
+
- rvm: ruby-head
|
105
|
+
jdk: oraclejdk8
|
106
|
+
- rvm: rbx-2
|
107
|
+
jdk: oraclejdk10
|
108
|
+
- rvm: 2.0.0
|
109
|
+
jdk: oraclejdk10
|
110
|
+
- rvm: 2.1
|
111
|
+
jdk: oraclejdk10
|
112
|
+
- rvm: 2.2.5
|
113
|
+
jdk: oraclejdk10
|
114
|
+
- rvm: 2.3.1
|
115
|
+
jdk: oraclejdk10
|
116
|
+
- rvm: 2.4.0
|
117
|
+
jdk: oraclejdk10
|
118
|
+
- rvm: 2.5.0
|
119
|
+
jdk: oraclejdk10
|
120
|
+
- rvm: ruby-head
|
121
|
+
jdk: oraclejdk10
|
122
|
+
- rvm: rbx-2
|
123
|
+
jdk: openjdk10
|
88
124
|
- rvm: 2.0.0
|
89
125
|
jdk: openjdk10
|
90
126
|
- rvm: 2.1
|
@@ -97,8 +133,10 @@ matrix:
|
|
97
133
|
jdk: openjdk10
|
98
134
|
- rvm: 2.5.0
|
99
135
|
jdk: openjdk10
|
100
|
-
- rvm:
|
136
|
+
- rvm: ruby-head
|
101
137
|
jdk: openjdk10
|
138
|
+
- rvm: rbx-2
|
139
|
+
jdk: oraclejdk11
|
102
140
|
- rvm: 2.0.0
|
103
141
|
jdk: oraclejdk11
|
104
142
|
- rvm: 2.1
|
@@ -111,8 +149,10 @@ matrix:
|
|
111
149
|
jdk: oraclejdk11
|
112
150
|
- rvm: 2.5.0
|
113
151
|
jdk: oraclejdk11
|
114
|
-
- rvm:
|
115
|
-
jdk: oraclejdk11
|
152
|
+
- rvm: ruby-head
|
153
|
+
jdk: oraclejdk11
|
154
|
+
- rvm: rbx-2
|
155
|
+
jdk: openjdk11
|
116
156
|
- rvm: 2.0.0
|
117
157
|
jdk: openjdk11
|
118
158
|
- rvm: 2.1
|
@@ -125,69 +165,59 @@ matrix:
|
|
125
165
|
jdk: openjdk11
|
126
166
|
- rvm: 2.5.0
|
127
167
|
jdk: openjdk11
|
128
|
-
- rvm:
|
129
|
-
jdk: openjdk11
|
130
|
-
- rvm: 2.
|
131
|
-
|
132
|
-
- rvm
|
133
|
-
|
134
|
-
- rvm : jruby-9.2.11.1
|
135
|
-
gemfile: gemfiles/rails4.gemfile
|
136
|
-
- rvm: 2.0.0
|
137
|
-
gemfile: gemfiles/rails5_0.gemfile
|
138
|
-
- rvm: 2.1
|
139
|
-
gemfile: gemfiles/rails5_0.gemfile
|
140
|
-
- rvm: 2.7.1
|
141
|
-
gemfile: gemfiles/rails5.0.gemfile
|
168
|
+
- rvm: ruby-head
|
169
|
+
jdk: openjdk11
|
170
|
+
- rvm: jruby-9.2.0.0
|
171
|
+
jdk: openjdk7
|
172
|
+
- rvm: jruby-head
|
173
|
+
jdk: openjdk7
|
142
174
|
- rvm: 2.0.0
|
143
175
|
gemfile: gemfiles/rails5_1_4.gemfile
|
144
176
|
- rvm: 2.1
|
145
177
|
gemfile: gemfiles/rails5_1_4.gemfile
|
146
178
|
- rvm: 2.2.5
|
147
179
|
gemfile: gemfiles/rails5_1_4.gemfile
|
148
|
-
- rvm:
|
149
|
-
gemfile: gemfiles/
|
150
|
-
- rvm: 2.7.1
|
151
|
-
gemfile: gemfiles/rails5.1.4.gemfile
|
180
|
+
- rvm: ruby-head
|
181
|
+
gemfile: gemfiles/rails4.gemfile
|
152
182
|
- rvm: 2.0.0
|
153
|
-
gemfile: gemfiles/
|
183
|
+
gemfile: gemfiles/rails5_0.gemfile
|
154
184
|
- rvm: 2.1
|
155
|
-
gemfile: gemfiles/
|
156
|
-
- rvm:
|
157
|
-
gemfile: gemfiles/
|
158
|
-
- rvm: 2.7.1
|
159
|
-
gemfile: gemfiles/rails5.2.gemfile
|
185
|
+
gemfile: gemfiles/rails5_0.gemfile
|
186
|
+
- rvm: jruby-9.0.5.0
|
187
|
+
gemfile: gemfiles/rails5_1_4.gemfile
|
160
188
|
- rvm: 2.0.0
|
161
|
-
gemfile: gemfiles/
|
189
|
+
gemfile: gemfiles/rails5_2.gemfile
|
162
190
|
- rvm: 2.1
|
163
|
-
gemfile: gemfiles/
|
164
|
-
- rvm: 2.2.5
|
165
|
-
gemfile: gemfiles/rails6.gemfile
|
166
|
-
- rvm: 2.3.1
|
167
|
-
gemfile: gemfiles/rails6.gemfile
|
168
|
-
- rvm: 2.4.0
|
169
|
-
gemfile: gemfiles/rails6.gemfile
|
191
|
+
gemfile: gemfiles/rails5_2.gemfile
|
170
192
|
allow_failures:
|
171
|
-
- rvm:
|
172
|
-
gemfile: gemfiles/
|
173
|
-
- rvm:
|
193
|
+
- rvm: rbx-2
|
194
|
+
gemfile: gemfiles/rails4.gemfile
|
195
|
+
- rvm: rbx-2
|
196
|
+
gemfile: gemfiles/rails5_0.gemfile
|
197
|
+
- rvm: rbx-2
|
198
|
+
gemfile: gemfiles/rails5_1_4.gemfile
|
199
|
+
- rvm: rbx-2
|
174
200
|
gemfile: gemfiles/rails5_2.gemfile
|
175
|
-
- rvm:
|
201
|
+
- rvm: rbx-2
|
202
|
+
gemfile: gemfiles/rails5_1_4.gemfile
|
203
|
+
- rvm: jruby-9.0.5.0
|
204
|
+
gemfile: gemfiles/rails5_2.gemfile
|
205
|
+
- rvm: jruby-9.2.0.0
|
176
206
|
jdk: oraclejdk9
|
177
207
|
gemfile: gemfiles/rails5_2.gemfile
|
178
|
-
- jdk: oraclejdk9
|
179
208
|
- jdk: openjdk10
|
209
|
+
- jdk: oraclejdk10
|
180
210
|
- jdk: openjdk11
|
181
211
|
- jdk: oraclejdk11
|
212
|
+
- rvm: ruby-head
|
182
213
|
- rvm: jruby-head
|
183
|
-
- rvm: jruby-9.2.
|
214
|
+
- rvm: jruby-9.2.0.0
|
184
215
|
jdk: oraclejdk9
|
185
216
|
- rvm: jruby-9.0.5.0
|
186
217
|
jdk: oraclejdk9
|
187
|
-
- rvm: 2.7.1
|
188
|
-
- gemfile: gemfiles/rails6.gemfile
|
189
218
|
bundler_args: "--jobs 3 --retry 2"
|
190
219
|
notifications:
|
191
|
-
email:
|
192
|
-
|
193
|
-
|
220
|
+
email:
|
221
|
+
notifications:
|
222
|
+
- julien.delporte@faveod.com
|
223
|
+
- yann.azoury@faveod.com
|
data/Gemfile
CHANGED
@@ -1,24 +1,29 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
|
3
|
+
gem 'rails', '~> 6.0.0.rc2'
|
4
|
+
|
4
5
|
|
5
6
|
group :development, :test do
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
7
|
+
gem 'activesupport', '~> 6.0.0.rc2'
|
8
|
+
gem 'activemodel', '~> 6.0.0.rc2'
|
9
|
+
gem 'activerecord', '~> 6.0.0.rc2'
|
9
10
|
|
10
|
-
gem "
|
11
|
-
gem "
|
12
|
-
gem "
|
13
|
-
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
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
14
|
|
15
|
-
gem "tiny_tds",
|
16
|
-
gem "activerecord-sqlserver-adapter",
|
15
|
+
gem "tiny_tds", :platforms => [:mri, :mingw] if RUBY_PLATFORM =~ /windows/
|
16
|
+
gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
|
17
17
|
|
18
|
-
gem 'ruby-oci8', platforms
|
19
|
-
gem 'activerecord-oracle_enhanced-adapter', '~>
|
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'
|
20
20
|
|
21
|
-
|
22
|
-
gem '
|
23
|
-
gem
|
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
|
24
28
|
end
|
29
|
+
|
data/README.md
CHANGED
@@ -19,11 +19,6 @@ 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
|
-
[Rails Repository](http://github.com/rails/rails)
|
26
|
-
|
27
22
|
## Usage
|
28
23
|
|
29
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:
|
@@ -77,9 +72,9 @@ With Arel Extensions:
|
|
77
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
|
@@ -135,7 +130,7 @@ t[:birthdate].format('%Y-%m-%d').to_sql
|
|
135
130
|
# => DATE_FORMAT(my_table.birthdate, '%Y-%m-%d')
|
136
131
|
```
|
137
132
|
|
138
|
-
## Unions
|
133
|
+
## Unions
|
139
134
|
|
140
135
|
```ruby
|
141
136
|
(t.where(t[:name].eq('str')) + t.where(t[:name].eq('test'))).to_sql
|
@@ -148,7 +143,7 @@ Arel-extensions allows to use functions on case clause
|
|
148
143
|
|
149
144
|
```ruby
|
150
145
|
t[:name].when("smith").then(1).when("doe").then(2).else(0).sum.to_sql
|
151
|
-
# => 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)
|
152
147
|
```
|
153
148
|
|
154
149
|
## Cast Function
|
@@ -165,7 +160,7 @@ t[:id].cast('char').to_sql
|
|
165
160
|
|
166
161
|
To optimize queries, some classical functions are defined in databases missing any alternative native functions.
|
167
162
|
Examples :
|
168
|
-
- FIND_IN_SET
|
163
|
+
- FIND_IN_SET
|
169
164
|
|
170
165
|
## BULK INSERT / UPSERT
|
171
166
|
|
@@ -214,7 +209,7 @@ User.connection.execute(insert_manager.to_sql)
|
|
214
209
|
<td class="tg-yw4l">CEIL<br>column.ceil</td>
|
215
210
|
<td class="ok">✔</td>
|
216
211
|
<td class="ok">✔</td>
|
217
|
-
<td class="tg-j6lv">CASE +
|
212
|
+
<td class="tg-j6lv">CASE + ROUND</td>
|
218
213
|
<td class="ok">✔</td>
|
219
214
|
<td class="tg-j6lv">CEILING()</td>
|
220
215
|
<td class="tg-j6lv">CEILING()</td>
|
@@ -223,7 +218,7 @@ User.connection.execute(insert_manager.to_sql)
|
|
223
218
|
<td class="tg-yw4l">FLOOR<br>column.floor</td>
|
224
219
|
<td class="ok">✔</td>
|
225
220
|
<td class="ok">✔</td>
|
226
|
-
<td class="tg-j6lv">CASE +
|
221
|
+
<td class="tg-j6lv">CASE + ROUND</td>
|
227
222
|
<td class="ok">✔</td>
|
228
223
|
<td class="ok">✔</td>
|
229
224
|
<td class="ok">✔</td>
|
@@ -390,7 +385,7 @@ User.connection.execute(insert_manager.to_sql)
|
|
390
385
|
<td class="ok">✔</td>
|
391
386
|
<td class="tg-j6lv">✔</td>
|
392
387
|
<td class="tg-j6lv">?</td>
|
393
|
-
</tr>
|
388
|
+
</tr>
|
394
389
|
<tr>
|
395
390
|
<td class="tg-yw4l">Matching Accent Insensitive<br>column.ai_matches('blah')</td>
|
396
391
|
<td class="ok">not supported</td>
|
@@ -399,7 +394,7 @@ User.connection.execute(insert_manager.to_sql)
|
|
399
394
|
<td class="ok">not supported</td>
|
400
395
|
<td class="tg-j6lv">✔</td>
|
401
396
|
<td class="tg-j6lv">?</td>
|
402
|
-
</tr>
|
397
|
+
</tr>
|
403
398
|
<tr>
|
404
399
|
<td class="tg-yw4l">Matching Case Insensitive<br>column.imatches('blah')</td>
|
405
400
|
<td class="ok">not supported</td>
|
@@ -408,7 +403,7 @@ User.connection.execute(insert_manager.to_sql)
|
|
408
403
|
<td class="ok">✔</td>
|
409
404
|
<td class="tg-j6lv">✔</td>
|
410
405
|
<td class="tg-j6lv">?</td>
|
411
|
-
</tr>
|
406
|
+
</tr>
|
412
407
|
<tr>
|
413
408
|
<td class="tg-yw4l">Matching Accent/Case Sensitive<br>column.smatches('blah')</td>
|
414
409
|
<td class="ok">✔</td>
|
@@ -417,8 +412,8 @@ User.connection.execute(insert_manager.to_sql)
|
|
417
412
|
<td class="ok">✔</td>
|
418
413
|
<td class="tg-j6lv">✔</td>
|
419
414
|
<td class="tg-j6lv">?</td>
|
420
|
-
</tr>
|
421
|
-
|
415
|
+
</tr>
|
416
|
+
|
422
417
|
<tr>
|
423
418
|
<th class="tg-4rp9" rowspan="6"><div>Date functions</div></th>
|
424
419
|
<td class="tg-yw4l">DATEADD<br>column + 2.year<br></td>
|
data/Rakefile
CHANGED
@@ -1,50 +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
6
|
desc "Default Task"
|
7
|
-
task default: [:test]
|
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}"]
|
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}"]
|
50
39
|
end
|
data/appveyor.yml
CHANGED
data/arel_extensions.gemspec
CHANGED
@@ -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('
|
23
|
+
s.add_dependency('activerecord', '>= 6.0.0.rc2')
|
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', '~>
|
28
|
-
end
|
27
|
+
s.add_development_dependency('rake', '~> 11')
|
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 +
|
58
|
+
<td class="tg-j6lv">CASE + ROUND</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 +
|
67
|
+
<td class="tg-j6lv">CASE + ROUND</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>
|
data/gemfiles/rails3.gemfile
CHANGED
@@ -3,18 +3,18 @@ source "https://rubygems.org"
|
|
3
3
|
gem 'arel', '~> 3.0' # too old...
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
-
gem "sqlite3", '<= 1.3.13', platform
|
7
|
-
gem "mysql2", '0.4.10', platform
|
8
|
-
gem "activerecord-mysql2-adapter", platform
|
9
|
-
gem "pg", platform
|
6
|
+
gem "sqlite3", '<= 1.3.13', :platform => [:ruby, :mswin, :mingw]
|
7
|
+
gem "mysql2", '0.4.10', :platform => [:ruby, :mswin, :mingw]
|
8
|
+
gem "activerecord-mysql2-adapter", :platform => [:ruby, :mswin, :mingw]
|
9
|
+
gem "pg", :platform => [:ruby, :mswin, :mingw]
|
10
10
|
# for JRuby
|
11
|
-
gem "jdbc-sqlite3", platform
|
12
|
-
gem "activerecord-jdbcsqlite3-adapter", platform
|
13
|
-
gem "activerecord-jdbcmysql-adapter", platform
|
14
|
-
gem "activerecord-jdbcpostgresql-adapter", platform
|
11
|
+
gem "jdbc-sqlite3", :platform => :jruby
|
12
|
+
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
|
13
|
+
gem "activerecord-jdbcmysql-adapter", :platform => :jruby
|
14
|
+
gem "activerecord-jdbcpostgresql-adapter", :platform => :jruby
|
15
15
|
gem 'activesupport', '~> 3.2'
|
16
16
|
gem 'activemodel', '~> 3.2'
|
17
17
|
gem 'activerecord', '~> 3.2'
|
18
18
|
end
|
19
19
|
|
20
|
-
gemspec path
|
20
|
+
gemspec :path => "../"
|
data/gemfiles/rails4.gemfile
CHANGED
@@ -7,23 +7,23 @@ group :development, :test do
|
|
7
7
|
gem 'activemodel', '~> 4.0'
|
8
8
|
gem 'activerecord', '~> 4.0'
|
9
9
|
|
10
|
-
gem "sqlite3", '<= 1.3.13', platforms
|
11
|
-
gem "mysql2", '0.4.10', platforms
|
12
|
-
gem "pg",'< 1.0.0', platforms
|
10
|
+
gem "sqlite3", '<= 1.3.13', :platforms => [:mri, :mswin, :mingw]
|
11
|
+
gem "mysql2", '0.4.10', :platforms => [:mri, :mswin, :mingw]
|
12
|
+
gem "pg",'< 1.0.0', :platforms => [:mri, :mingw]
|
13
13
|
|
14
|
-
gem "tiny_tds", platforms
|
15
|
-
gem "activerecord-sqlserver-adapter", '~> 4.2.0', platforms
|
14
|
+
gem "tiny_tds", :platforms => [:mri, :mingw, :mswin] if RUBY_PLATFORM =~ /windows/
|
15
|
+
gem "activerecord-sqlserver-adapter", '~> 4.2.0', :platforms => [:mri, :mingw, :mswin] if RUBY_PLATFORM =~ /windows/
|
16
16
|
|
17
|
-
gem 'ruby-oci8', platforms
|
17
|
+
gem 'ruby-oci8', :platforms => [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
|
18
18
|
gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0' if ENV.has_key? 'ORACLE_HOME'
|
19
19
|
|
20
20
|
# for JRuby
|
21
|
-
gem 'activerecord-jdbc-adapter',
|
22
|
-
gem "jdbc-sqlite3", platforms
|
23
|
-
gem "activerecord-jdbcsqlite3-adapter", platforms
|
24
|
-
gem "activerecord-jdbcmysql-adapter", platforms
|
25
|
-
gem "activerecord-jdbcpostgresql-adapter", platforms
|
26
|
-
gem "activerecord-jdbcmssql-adapter", platforms
|
21
|
+
gem 'activerecord-jdbc-adapter', :platforms => :jruby
|
22
|
+
gem "jdbc-sqlite3", :platforms => :jruby
|
23
|
+
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
|
24
|
+
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
|
25
|
+
gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
|
26
|
+
gem "activerecord-jdbcmssql-adapter", :platforms => :jruby
|
27
27
|
end
|
28
28
|
|
29
|
-
gemspec path
|
29
|
+
gemspec :path => "../"
|