arel_extensions 2.0.1 → 2.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -4
- data/.travis.yml +59 -91
- data/Gemfile +14 -19
- data/README.md +17 -12
- data/Rakefile +38 -27
- data/appveyor.yml +1 -1
- data/arel_extensions.gemspec +2 -2
- data/functions.html +3 -3
- data/gemfiles/rails4.gemfile +1 -1
- data/gemfiles/rails6.gemfile +30 -0
- data/gemspec_v2/arel_extensions-v2.gemspec +28 -0
- data/generate_gems.sh +14 -0
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/postgresql.sql +21 -21
- data/lib/arel_extensions.rb +63 -19
- data/lib/arel_extensions/attributes.rb +0 -1
- data/lib/arel_extensions/boolean_functions.rb +38 -13
- data/lib/arel_extensions/common_sql_functions.rb +5 -4
- data/lib/arel_extensions/comparators.rb +4 -2
- data/lib/arel_extensions/insert_manager.rb +15 -13
- data/lib/arel_extensions/math.rb +3 -3
- data/lib/arel_extensions/math_functions.rb +10 -5
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/nodes/abs.rb +0 -0
- data/lib/arel_extensions/nodes/aggregate_function.rb +14 -0
- data/lib/arel_extensions/nodes/case.rb +8 -4
- data/lib/arel_extensions/nodes/ceil.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +2 -2
- data/lib/arel_extensions/nodes/collate.rb +1 -1
- data/lib/arel_extensions/nodes/concat.rb +6 -13
- data/lib/arel_extensions/nodes/date_diff.rb +3 -5
- data/lib/arel_extensions/nodes/duration.rb +0 -2
- data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
- data/lib/arel_extensions/nodes/floor.rb +0 -0
- data/lib/arel_extensions/nodes/format.rb +8 -8
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -23
- data/lib/arel_extensions/nodes/function.rb +2 -0
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +43 -30
- data/lib/arel_extensions/nodes/length.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +0 -0
- data/lib/arel_extensions/nodes/matches.rb +4 -4
- data/lib/arel_extensions/nodes/power.rb +6 -5
- data/lib/arel_extensions/nodes/rand.rb +0 -0
- data/lib/arel_extensions/nodes/repeat.rb +2 -2
- data/lib/arel_extensions/nodes/replace.rb +24 -6
- data/lib/arel_extensions/nodes/round.rb +5 -5
- data/lib/arel_extensions/nodes/soundex.rb +16 -15
- data/lib/arel_extensions/nodes/std.rb +19 -21
- data/lib/arel_extensions/nodes/substring.rb +8 -15
- data/lib/arel_extensions/nodes/sum.rb +7 -0
- data/lib/arel_extensions/nodes/trim.rb +3 -3
- data/lib/arel_extensions/nodes/union.rb +2 -3
- data/lib/arel_extensions/nodes/union_all.rb +0 -1
- data/lib/arel_extensions/nodes/wday.rb +0 -0
- data/lib/arel_extensions/null_functions.rb +2 -2
- data/lib/arel_extensions/predications.rb +35 -33
- data/lib/arel_extensions/set_functions.rb +2 -2
- data/lib/arel_extensions/string_functions.rb +34 -12
- data/lib/arel_extensions/tasks.rb +5 -5
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors.rb +1 -1
- data/lib/arel_extensions/visitors/ibm_db.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +14 -13
- data/lib/arel_extensions/visitors/mysql.rb +89 -39
- data/lib/arel_extensions/visitors/oracle.rb +15 -15
- data/lib/arel_extensions/visitors/oracle12.rb +1 -1
- data/lib/arel_extensions/visitors/postgresql.rb +78 -32
- data/lib/arel_extensions/visitors/sqlite.rb +61 -53
- data/lib/arel_extensions/visitors/to_sql.rb +93 -73
- data/test/arelx_test_helper.rb +28 -0
- data/test/real_db_test.rb +1 -1
- data/test/support/fake_record.rb +1 -1
- data/test/test_comparators.rb +9 -8
- data/test/visitors/test_bulk_insert_oracle.rb +8 -7
- data/test/visitors/test_bulk_insert_sqlite.rb +9 -8
- data/test/visitors/test_bulk_insert_to_sql.rb +8 -10
- data/test/visitors/test_oracle.rb +41 -40
- data/test/visitors/test_to_sql.rb +367 -193
- data/test/with_ar/all_agnostic_test.rb +68 -35
- data/test/with_ar/insert_agnostic_test.rb +3 -2
- data/test/with_ar/test_bulk_sqlite.rb +6 -5
- data/test/with_ar/test_math_sqlite.rb +4 -4
- data/test/with_ar/test_string_mysql.rb +4 -6
- data/test/with_ar/test_string_sqlite.rb +3 -7
- data/version_v1.rb +3 -0
- data/version_v2.rb +3 -0
- metadata +14 -7
- data/test/helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ecd7512b41f7db6706dd6affb2e57327cf7331233e39027906743f824f82a8
|
4
|
+
data.tar.gz: 1c7baed7dedb0fb616116fd9888dff8e3a9b0c15ff9b2ae107b982adb522e67c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a81f1010f6cf3d992830b1596eb5b8eaf61fd725cbe97f4cea23aea8172d2f6f6377b58684cf00b16da947ab9a1b65f23efe6f9335db274764931772cb7a219e
|
7
|
+
data.tar.gz: d5140b1fcbff6e4a9549d0d0418ed95215405f8f78ae8e82d6a7a86792130f4e31272cfcd6733c511cc2828599f466a2d66c0b8ffcc461a6d2c7ffe81307c369
|
data/.rubocop.yml
CHANGED
@@ -12,7 +12,10 @@ Layout/ExtraSpacing:
|
|
12
12
|
Layout/SpaceAroundEqualsInParameterDefault:
|
13
13
|
Enabled: true
|
14
14
|
|
15
|
-
Layout/
|
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
@@ -1,5 +1,6 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: required
|
3
|
+
dist: trusty
|
3
4
|
cache:
|
4
5
|
bundler: true
|
5
6
|
directories:
|
@@ -15,21 +16,23 @@ before_install:
|
|
15
16
|
# - sh -ex .travis/oracle/install.sh
|
16
17
|
# - .travis/setup_accounts.sh
|
17
18
|
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
|
25
26
|
services:
|
26
27
|
- mysql
|
27
28
|
- postgresql
|
29
|
+
addons:
|
30
|
+
postgresql: '9.4'
|
28
31
|
before_script:
|
29
32
|
- mysql -e 'create database arext_test;'
|
30
33
|
- psql -c 'create database arext_test;' -U postgres
|
31
34
|
script:
|
32
|
-
-
|
35
|
+
- ./generate_gems.sh
|
33
36
|
- bundle exec rake test
|
34
37
|
- bundle exec rake test:sqlite
|
35
38
|
- bundle exec rake test:mysql
|
@@ -55,72 +58,33 @@ rvm:
|
|
55
58
|
- 2.3.1
|
56
59
|
- 2.4.0
|
57
60
|
- 2.5.0
|
58
|
-
-
|
61
|
+
- 2.7.1
|
59
62
|
- jruby-9.0.5.0
|
60
|
-
- jruby-9.2.
|
63
|
+
- jruby-9.2.11.1
|
61
64
|
- jruby-head
|
62
|
-
- ruby-head
|
63
65
|
jdk:
|
64
|
-
- openjdk7
|
65
66
|
- oraclejdk8
|
66
67
|
- oraclejdk9
|
67
68
|
- 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
|
76
74
|
- rvm: 2.0.0
|
77
|
-
jdk:
|
78
|
-
- rvm: 2.1
|
79
|
-
jdk: openjdk7
|
80
|
-
- rvm: 2.2.5
|
81
|
-
jdk: openjdk7
|
82
|
-
- rvm: 2.3.1
|
83
|
-
jdk: openjdk7
|
84
|
-
- rvm: 2.4.0
|
85
|
-
jdk: openjdk7
|
86
|
-
- rvm: 2.5.0
|
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
|
75
|
+
jdk: oraclejdk9
|
110
76
|
- rvm: 2.1
|
111
|
-
jdk:
|
77
|
+
jdk: oraclejdk9
|
112
78
|
- rvm: 2.2.5
|
113
|
-
jdk:
|
79
|
+
jdk: oraclejdk9
|
114
80
|
- rvm: 2.3.1
|
115
|
-
jdk:
|
81
|
+
jdk: oraclejdk9
|
116
82
|
- rvm: 2.4.0
|
117
|
-
jdk:
|
83
|
+
jdk: oraclejdk9
|
118
84
|
- rvm: 2.5.0
|
119
|
-
jdk:
|
120
|
-
- rvm:
|
121
|
-
jdk:
|
122
|
-
- rvm: rbx-2
|
123
|
-
jdk: openjdk10
|
85
|
+
jdk: oraclejdk9
|
86
|
+
- rvm: 2.7.1
|
87
|
+
jdk: oraclejdk9
|
124
88
|
- rvm: 2.0.0
|
125
89
|
jdk: openjdk10
|
126
90
|
- rvm: 2.1
|
@@ -133,10 +97,8 @@ matrix:
|
|
133
97
|
jdk: openjdk10
|
134
98
|
- rvm: 2.5.0
|
135
99
|
jdk: openjdk10
|
136
|
-
- rvm:
|
100
|
+
- rvm: 2.7.1
|
137
101
|
jdk: openjdk10
|
138
|
-
- rvm: rbx-2
|
139
|
-
jdk: oraclejdk11
|
140
102
|
- rvm: 2.0.0
|
141
103
|
jdk: oraclejdk11
|
142
104
|
- rvm: 2.1
|
@@ -149,10 +111,8 @@ matrix:
|
|
149
111
|
jdk: oraclejdk11
|
150
112
|
- rvm: 2.5.0
|
151
113
|
jdk: oraclejdk11
|
152
|
-
- rvm:
|
153
|
-
jdk: oraclejdk11
|
154
|
-
- rvm: rbx-2
|
155
|
-
jdk: openjdk11
|
114
|
+
- rvm: 2.7.1
|
115
|
+
jdk: oraclejdk11
|
156
116
|
- rvm: 2.0.0
|
157
117
|
jdk: openjdk11
|
158
118
|
- rvm: 2.1
|
@@ -165,59 +125,67 @@ matrix:
|
|
165
125
|
jdk: openjdk11
|
166
126
|
- rvm: 2.5.0
|
167
127
|
jdk: openjdk11
|
168
|
-
- rvm:
|
169
|
-
jdk: openjdk11
|
170
|
-
- rvm:
|
171
|
-
|
172
|
-
- rvm: jruby-
|
173
|
-
|
128
|
+
- rvm: 2.7.1
|
129
|
+
jdk: openjdk11
|
130
|
+
- rvm: 2.7.1
|
131
|
+
gemfile: gemfiles/rails4.gemfile
|
132
|
+
- rvm : jruby-9.2.11.1
|
133
|
+
gemfile: gemfiles/rails4.gemfile
|
134
|
+
- rvm: 2.0.0
|
135
|
+
gemfile: gemfiles/rails5_0.gemfile
|
136
|
+
- rvm: 2.1
|
137
|
+
gemfile: gemfiles/rails5_0.gemfile
|
138
|
+
- rvm: 2.7.1
|
139
|
+
gemfile: gemfiles/rails5.0.gemfile
|
174
140
|
- rvm: 2.0.0
|
175
141
|
gemfile: gemfiles/rails5_1_4.gemfile
|
176
142
|
- rvm: 2.1
|
177
143
|
gemfile: gemfiles/rails5_1_4.gemfile
|
178
144
|
- rvm: 2.2.5
|
179
145
|
gemfile: gemfiles/rails5_1_4.gemfile
|
180
|
-
- rvm:
|
181
|
-
gemfile: gemfiles/
|
182
|
-
- rvm: 2.
|
183
|
-
gemfile: gemfiles/
|
184
|
-
- rvm: 2.1
|
185
|
-
gemfile: gemfiles/rails5_0.gemfile
|
186
|
-
- rvm: jruby-9.0.5.0
|
187
|
-
gemfile: gemfiles/rails5_1_4.gemfile
|
146
|
+
- rvm: 2.7.1
|
147
|
+
gemfile: gemfiles/rails5.1.4.gemfile
|
148
|
+
- rvm: 2.7.1
|
149
|
+
gemfile: gemfiles/rails5.1.4.gemfile
|
188
150
|
- rvm: 2.0.0
|
189
151
|
gemfile: gemfiles/rails5_2.gemfile
|
190
152
|
- rvm: 2.1
|
191
153
|
gemfile: gemfiles/rails5_2.gemfile
|
192
|
-
|
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
|
154
|
+
- rvm: 2.2.5
|
200
155
|
gemfile: gemfiles/rails5_2.gemfile
|
201
|
-
- rvm:
|
156
|
+
- rvm: 2.7.1
|
157
|
+
gemfile: gemfiles/rails5.2.gemfile
|
158
|
+
- rvm: 2.0.0
|
159
|
+
gemfile: gemfiles/rails6.gemfile
|
160
|
+
- rvm: 2.1
|
161
|
+
gemfile: gemfiles/rails6.gemfile
|
162
|
+
- rvm: 2.2.5
|
163
|
+
gemfile: gemfiles/rails6.gemfile
|
164
|
+
- rvm: 2.3.1
|
165
|
+
gemfile: gemfiles/rails6.gemfile
|
166
|
+
- rvm: 2.4.0
|
167
|
+
gemfile: gemfiles/rails6.gemfile
|
168
|
+
allow_failures:
|
169
|
+
- rvm: jruby-9.0.5.0
|
202
170
|
gemfile: gemfiles/rails5_1_4.gemfile
|
203
|
-
- rvm: jruby-9.0.5.0
|
204
|
-
gemfile: gemfiles/rails5_2.gemfile
|
205
|
-
- rvm: jruby-9.2.
|
171
|
+
- rvm: jruby-9.0.5.0
|
172
|
+
gemfile: gemfiles/rails5_2.gemfile
|
173
|
+
- rvm: jruby-9.2.11.1
|
206
174
|
jdk: oraclejdk9
|
207
175
|
gemfile: gemfiles/rails5_2.gemfile
|
176
|
+
- jdk: oraclejdk9
|
208
177
|
- jdk: openjdk10
|
209
|
-
- jdk: oraclejdk10
|
210
178
|
- jdk: openjdk11
|
211
179
|
- jdk: oraclejdk11
|
212
|
-
- rvm: ruby-head
|
213
180
|
- rvm: jruby-head
|
214
|
-
- rvm: jruby-9.2.
|
181
|
+
- rvm: jruby-9.2.11.1
|
215
182
|
jdk: oraclejdk9
|
216
183
|
- rvm: jruby-9.0.5.0
|
217
184
|
jdk: oraclejdk9
|
185
|
+
- rvm: 2.7.1
|
186
|
+
- gemfile: gemfiles/rails6.gemfile
|
218
187
|
bundler_args: "--jobs 3 --retry 2"
|
219
188
|
notifications:
|
220
|
-
email:
|
221
|
-
|
222
|
-
|
223
|
-
- yann.azoury@faveod.com
|
189
|
+
email:
|
190
|
+
- julien.delporte@faveod.com
|
191
|
+
- yann.azoury@faveod.com
|
data/Gemfile
CHANGED
@@ -1,29 +1,24 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
gemspec
|
5
4
|
|
6
5
|
group :development, :test do
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem '
|
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
|
+
[Rails 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 +
|
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 +
|
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,44 @@ desc "Default Task"
|
|
7
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
|
-
|
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}"]
|
39
50
|
end
|