arel_extensions 1.3.0 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +258 -52
- data/Gemfile +8 -8
- data/README.md +65 -0
- data/gemfiles/rails5_2.gemfile +3 -3
- data/gemfiles/rails6.gemfile +3 -4
- data/gemfiles/rails6_1.gemfile +1 -2
- data/gemfiles/rails7.gemfile +5 -13
- data/lib/arel_extensions/date_duration.rb +2 -2
- data/lib/arel_extensions/helpers.rb +48 -0
- data/lib/arel_extensions/math.rb +17 -27
- data/lib/arel_extensions/nodes/case.rb +3 -5
- data/lib/arel_extensions/nodes/date_diff.rb +23 -4
- data/lib/arel_extensions/nodes/format.rb +3 -2
- data/lib/arel_extensions/nodes/function.rb +1 -7
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +126 -53
- data/lib/arel_extensions/visitors/mysql.rb +15 -0
- data/lib/arel_extensions/visitors/oracle.rb +14 -1
- data/lib/arel_extensions/visitors/postgresql.rb +20 -7
- data/lib/arel_extensions/visitors/sqlite.rb +6 -3
- data/lib/arel_extensions.rb +11 -1
- data/test/arelx_test_helper.rb +45 -1
- data/test/database.yml +8 -2
- data/test/support/fake_record.rb +1 -1
- data/test/visitors/test_to_sql.rb +21 -0
- data/test/with_ar/all_agnostic_test.rb +103 -3
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +3 -3
- data/appveyor.yml +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4f994a5cce5bea002ac1274171d392e20f9119b45609484fc7b6a97c71aeef5
|
4
|
+
data.tar.gz: 7dae52792c8713f7c129c5c8870939cfc397ec8e2fb07a980bdba318a4c5fcd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77c8c7c4767f2c2ee617e001c2966bf6d6ad53daa2026ceb71efd337ebdfe1a2e2af080734f522f659a71ad1569052bd1c4730cde4d34f7577899245b50915a3
|
7
|
+
data.tar.gz: 71d6d5420d2515caecddc02613819bb2b2b06a5aed6f66d06e8d9397f2af6b478f97b6798746f91cc116fb4199aca4f4c61c98b45a0aa6cca9b8a0e821b90f83
|
data/.github/workflows/ruby.yml
CHANGED
@@ -11,15 +11,17 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
|
-
ruby: [3.1, 3.0, 2.7, 2.5]
|
14
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
15
15
|
rails: [7, 6_1, 6, 5_2]
|
16
16
|
exclude: [
|
17
|
-
{ruby: 3.1,
|
18
|
-
{ruby: 3.1,
|
19
|
-
{ruby: 3.0,
|
20
|
-
{ruby: 3.0,
|
21
|
-
{ruby: 2.7,
|
22
|
-
{ruby: 2.5,
|
17
|
+
{ruby: 3.1, rails: 6 },
|
18
|
+
{ruby: 3.1, rails: 5_2},
|
19
|
+
{ruby: 3.0, rails: 6 },
|
20
|
+
{ruby: 3.0, rails: 5_2},
|
21
|
+
{ruby: 2.7, rails: 5_2},
|
22
|
+
{ruby: 2.5, rails: 7 },
|
23
|
+
{ruby: jruby-9.2, rails: 7 },
|
24
|
+
{ruby: jruby-9.3, rails: 7 },
|
23
25
|
]
|
24
26
|
steps:
|
25
27
|
- uses: actions/checkout@v2
|
@@ -28,7 +30,7 @@ jobs:
|
|
28
30
|
with:
|
29
31
|
ruby-version: ${{ matrix.ruby }}
|
30
32
|
- name: Setup gemspec
|
31
|
-
if: ${{ matrix.rails
|
33
|
+
if: ${{ matrix.rails != '5_2' }}
|
32
34
|
run: |
|
33
35
|
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
34
36
|
cp ./version_v2.rb lib/arel_extensions/version.rb
|
@@ -41,28 +43,127 @@ jobs:
|
|
41
43
|
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
42
44
|
path: "*.gem"
|
43
45
|
|
44
|
-
|
45
|
-
name: test
|
46
|
+
job_test_to_sql:
|
47
|
+
name: test to_sql
|
46
48
|
needs: job_build_gem
|
47
49
|
runs-on: ubuntu-latest
|
48
50
|
strategy:
|
49
51
|
fail-fast: false
|
50
52
|
matrix:
|
51
|
-
ruby: [3.1, 3.0, 2.7, 2.5]
|
53
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
54
|
+
rails: [7, 6_1, 6, 5_2]
|
55
|
+
exclude: [
|
56
|
+
{ruby: 3.1, rails: 6 },
|
57
|
+
{ruby: 3.1, rails: 5_2},
|
58
|
+
{ruby: 3.0, rails: 6 },
|
59
|
+
{ruby: 3.0, rails: 5_2},
|
60
|
+
{ruby: 2.7, rails: 5_2},
|
61
|
+
{ruby: 2.5, rails: 7 },
|
62
|
+
{ruby: jruby-9.2, rails: 7},
|
63
|
+
{ruby: jruby-9.3, rails: 7},
|
64
|
+
]
|
65
|
+
steps:
|
66
|
+
- uses: actions/checkout@v2
|
67
|
+
- name: Set up Ruby
|
68
|
+
uses: ruby/setup-ruby@v1
|
69
|
+
with:
|
70
|
+
ruby-version: ${{ matrix.ruby }}
|
71
|
+
- name: Install FreeTDS
|
72
|
+
run: |
|
73
|
+
sudo apt-get update -q
|
74
|
+
sudo apt-get install -y freetds-dev
|
75
|
+
- name: Update system-wide gems
|
76
|
+
run: gem update --system
|
77
|
+
- name: Download gem from build job
|
78
|
+
uses: actions/download-artifact@v2
|
79
|
+
with:
|
80
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
81
|
+
- name: Setup Gemfile
|
82
|
+
if: ${{ matrix.rails != '5_2' }}
|
83
|
+
run: |
|
84
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
85
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
86
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
87
|
+
- name: bundle install
|
88
|
+
run: |
|
89
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
90
|
+
bundle install
|
91
|
+
- name: Run test to_sql
|
92
|
+
run: bundle exec rake test:to_sql
|
93
|
+
|
94
|
+
job_test_sqlite:
|
95
|
+
name: test sqlite
|
96
|
+
needs: job_build_gem
|
97
|
+
runs-on: ubuntu-latest
|
98
|
+
strategy:
|
99
|
+
fail-fast: false
|
100
|
+
matrix:
|
101
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
52
102
|
rails: [7, 6_1, 6, 5_2]
|
53
103
|
exclude: [
|
54
|
-
{ruby: 3.1,
|
55
|
-
{ruby: 3.1,
|
56
|
-
{ruby: 3.0,
|
57
|
-
{ruby: 3.0,
|
58
|
-
{ruby: 2.7,
|
59
|
-
{ruby: 2.5,
|
104
|
+
{ruby: 3.1, rails: 6 },
|
105
|
+
{ruby: 3.1, rails: 5_2},
|
106
|
+
{ruby: 3.0, rails: 6 },
|
107
|
+
{ruby: 3.0, rails: 5_2},
|
108
|
+
{ruby: 2.7, rails: 5_2},
|
109
|
+
{ruby: 2.5, rails: 7 },
|
110
|
+
{ruby: jruby-9.2, rails: 7},
|
111
|
+
{ruby: jruby-9.3, rails: 7},
|
112
|
+
]
|
113
|
+
steps:
|
114
|
+
- uses: actions/checkout@v2
|
115
|
+
- name: Set up Ruby
|
116
|
+
uses: ruby/setup-ruby@v1
|
117
|
+
with:
|
118
|
+
ruby-version: ${{ matrix.ruby }}
|
119
|
+
- name: Install FreeTDS
|
120
|
+
run: |
|
121
|
+
sudo apt-get update -q
|
122
|
+
sudo apt-get install -y freetds-dev
|
123
|
+
- name: Update system-wide gems
|
124
|
+
run: gem update --system
|
125
|
+
- name: Download gem from build job
|
126
|
+
uses: actions/download-artifact@v2
|
127
|
+
with:
|
128
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
129
|
+
- name: Setup Gemfile
|
130
|
+
if: ${{ matrix.rails != '5_2' }}
|
131
|
+
run: |
|
132
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
133
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
134
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
135
|
+
- name: bundle install
|
136
|
+
run: |
|
137
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
138
|
+
bundle install
|
139
|
+
- name: Run test sqlite
|
140
|
+
run: bundle exec rake test:sqlite
|
141
|
+
|
142
|
+
job_test_postgres:
|
143
|
+
name: test postgres
|
144
|
+
needs: job_build_gem
|
145
|
+
runs-on: ubuntu-latest
|
146
|
+
strategy:
|
147
|
+
fail-fast: false
|
148
|
+
matrix:
|
149
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
150
|
+
rails: [7, 6_1, 6, 5_2]
|
151
|
+
exclude: [
|
152
|
+
{ruby: 3.1, rails: 6 },
|
153
|
+
{ruby: 3.1, rails: 5_2},
|
154
|
+
{ruby: 3.0, rails: 6 },
|
155
|
+
{ruby: 3.0, rails: 5_2},
|
156
|
+
{ruby: 2.7, rails: 5_2},
|
157
|
+
{ruby: 2.5, rails: 7 },
|
158
|
+
{ruby: jruby-9.2, rails: 7},
|
159
|
+
{ruby: jruby-9.3, rails: 7},
|
60
160
|
]
|
61
161
|
services:
|
62
162
|
postgres:
|
63
163
|
image: postgres:11.6-alpine
|
64
164
|
env:
|
65
165
|
POSTGRES_DB: arext_test
|
166
|
+
POSTGRES_PASSWORD: secret
|
66
167
|
ports:
|
67
168
|
- 5432:5432
|
68
169
|
# needed because the postgres container does not provide a healthcheck
|
@@ -71,11 +172,63 @@ jobs:
|
|
71
172
|
--health-interval 10s
|
72
173
|
--health-timeout 5s
|
73
174
|
--health-retries 5
|
175
|
+
steps:
|
176
|
+
- uses: actions/checkout@v2
|
177
|
+
- name: Set up Ruby
|
178
|
+
uses: ruby/setup-ruby@v1
|
179
|
+
with:
|
180
|
+
ruby-version: ${{ matrix.ruby }}
|
181
|
+
- name: Install FreeTDS
|
182
|
+
run: |
|
183
|
+
sudo apt-get update -q
|
184
|
+
sudo apt-get install -y freetds-dev
|
185
|
+
- name: Update system-wide gems
|
186
|
+
run: gem update --system
|
187
|
+
- name: Download gem from build job
|
188
|
+
uses: actions/download-artifact@v2
|
189
|
+
with:
|
190
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
191
|
+
- name: Setup Gemfile
|
192
|
+
if: ${{ matrix.rails != '5_2' }}
|
193
|
+
run: |
|
194
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
195
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
196
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
197
|
+
- name: bundle install
|
198
|
+
run: |
|
199
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
200
|
+
bundle install
|
201
|
+
- name: Run test Postgres
|
202
|
+
env:
|
203
|
+
PGHOST: localhost
|
204
|
+
PGUSER: postgres
|
205
|
+
run: bundle exec rake test:postgresql
|
206
|
+
|
207
|
+
job_test_mysql:
|
208
|
+
name: test mysql
|
209
|
+
needs: job_build_gem
|
210
|
+
runs-on: ubuntu-latest
|
211
|
+
strategy:
|
212
|
+
fail-fast: false
|
213
|
+
matrix:
|
214
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
215
|
+
rails: [7, 6_1, 6, 5_2]
|
216
|
+
exclude: [
|
217
|
+
{ruby: 3.1, rails: 6 },
|
218
|
+
{ruby: 3.1, rails: 5_2},
|
219
|
+
{ruby: 3.0, rails: 6 },
|
220
|
+
{ruby: 3.0, rails: 5_2},
|
221
|
+
{ruby: 2.7, rails: 5_2},
|
222
|
+
{ruby: 2.5, rails: 7 },
|
223
|
+
{ruby: jruby-9.2, rails: 7 },
|
224
|
+
{ruby: jruby-9.3, rails: 7 },
|
225
|
+
]
|
226
|
+
services:
|
74
227
|
mysql:
|
75
228
|
image: mysql:5.7
|
76
229
|
env:
|
77
230
|
MYSQL_ALLOW_EMPTY_PASSWORD: true
|
78
|
-
MYSQL_USERNAME:
|
231
|
+
MYSQL_USERNAME: root
|
79
232
|
MYSQL_DATABASE: arext_test
|
80
233
|
ports:
|
81
234
|
- 3306:3306
|
@@ -94,47 +247,90 @@ jobs:
|
|
94
247
|
run: |
|
95
248
|
sudo apt-get update -q
|
96
249
|
sudo apt-get install -y freetds-dev
|
97
|
-
- name: Install MSSQL 2019
|
98
|
-
uses: potatoqualitee/mssqlsuite@v1
|
99
|
-
with:
|
100
|
-
install: sqlengine, sqlclient, sqlpackage, localdb
|
101
|
-
sa-password: Password12!
|
102
250
|
- name: Update system-wide gems
|
103
251
|
run: gem update --system
|
104
|
-
- name: bundle install
|
105
|
-
run: |
|
106
|
-
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
107
|
-
bundle install
|
108
252
|
- name: Download gem from build job
|
109
253
|
uses: actions/download-artifact@v2
|
110
254
|
with:
|
111
255
|
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
112
|
-
- name:
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
256
|
+
- name: Setup Gemfile
|
257
|
+
if: ${{ matrix.rails != '5_2' }}
|
258
|
+
run: |
|
259
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
260
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
261
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
262
|
+
- name: bundle install
|
263
|
+
run: |
|
264
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
265
|
+
bundle install
|
121
266
|
- name: Run test MySql
|
122
267
|
env:
|
123
268
|
DB_CONNECTION: mysql
|
124
269
|
DB_HOST: 127.0.0.1
|
125
270
|
DB_PORT: 3306
|
126
271
|
DB_DATABASE: arext_test
|
127
|
-
DB_USERNAME:
|
272
|
+
DB_USERNAME: root
|
273
|
+
run: bundle exec rake test:mysql
|
274
|
+
|
275
|
+
job_test_mssql:
|
276
|
+
name: test mssql on linux
|
277
|
+
needs: job_build_gem
|
278
|
+
runs-on: ubuntu-latest
|
279
|
+
strategy:
|
280
|
+
fail-fast: false
|
281
|
+
matrix:
|
282
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
283
|
+
rails: [7, 6_1, 6, 5_2]
|
284
|
+
exclude: [
|
285
|
+
{ruby: 3.1, rails: 6 },
|
286
|
+
{ruby: 3.1, rails: 5_2 },
|
287
|
+
{ruby: 3.0, rails: 6 },
|
288
|
+
{ruby: 3.0, rails: 5_2 },
|
289
|
+
{ruby: 2.7, rails: 5_2 },
|
290
|
+
{ruby: 2.5, rails: 7 },
|
291
|
+
{ruby: jruby-9.2, rails: 7 },
|
292
|
+
{ruby: jruby-9.2, rails: 6_1 },
|
293
|
+
{ruby: jruby-9.2, rails: 6 },
|
294
|
+
{ruby: jruby-9.3, rails: 7 },
|
295
|
+
{ruby: jruby-9.3, rails: 6_1 },
|
296
|
+
{ruby: jruby-9.3, rails: 6 },
|
297
|
+
]
|
298
|
+
steps:
|
299
|
+
- uses: actions/checkout@v2
|
300
|
+
- name: Set up Ruby
|
301
|
+
uses: ruby/setup-ruby@v1
|
302
|
+
with:
|
303
|
+
ruby-version: ${{ matrix.ruby }}
|
304
|
+
- name: Install FreeTDS
|
128
305
|
run: |
|
129
|
-
|
130
|
-
|
131
|
-
|
306
|
+
sudo apt-get update -q
|
307
|
+
sudo apt-get install -y freetds-dev
|
308
|
+
- name: Install MSSQL 2019
|
309
|
+
uses: potatoqualitee/mssqlsuite@v1
|
310
|
+
with:
|
311
|
+
install: sqlengine, sqlclient, sqlpackage, localdb
|
312
|
+
sa-password: Password12!
|
313
|
+
- name: Update system-wide gems
|
314
|
+
run: gem update --system
|
315
|
+
- name: Download gem from build job
|
316
|
+
uses: actions/download-artifact@v2
|
317
|
+
with:
|
318
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
319
|
+
- name: Setup Gemfile
|
320
|
+
if: ${{ matrix.rails != '5_2' }}
|
321
|
+
run: |
|
322
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
323
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
324
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
325
|
+
- name: bundle install
|
326
|
+
run: |
|
327
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
328
|
+
bundle install
|
132
329
|
- name: Run test mssql
|
133
|
-
run: rake test:mssql
|
134
|
-
|
330
|
+
run: bundle exec rake test:mssql
|
135
331
|
|
136
332
|
job_test_windows:
|
137
|
-
name: test windows
|
333
|
+
name: test mssql on windows
|
138
334
|
needs: job_build_gem
|
139
335
|
runs-on: windows-latest
|
140
336
|
strategy:
|
@@ -143,12 +339,18 @@ jobs:
|
|
143
339
|
ruby: [3.1, 3.0, 2.7, 2.5]
|
144
340
|
rails: [7, 6_1, 6, 5_2]
|
145
341
|
exclude: [
|
146
|
-
{ruby: 3.1,
|
147
|
-
{ruby: 3.1,
|
148
|
-
{ruby: 3.0,
|
149
|
-
{ruby: 3.0,
|
150
|
-
{ruby: 2.7,
|
151
|
-
{ruby: 2.5,
|
342
|
+
{ruby: 3.1, rails: 6 },
|
343
|
+
{ruby: 3.1, rails: 5_2 },
|
344
|
+
{ruby: 3.0, rails: 6 },
|
345
|
+
{ruby: 3.0, rails: 5_2 },
|
346
|
+
{ruby: 2.7, rails: 5_2 },
|
347
|
+
{ruby: 2.5, rails: 7 },
|
348
|
+
{ruby: jruby-9.2, rails: 7 },
|
349
|
+
{ruby: jruby-9.2, rails: 6_1 },
|
350
|
+
{ruby: jruby-9.2, rails: 6 },
|
351
|
+
{ruby: jruby-9.3, rails: 7 },
|
352
|
+
{ruby: jruby-9.3, rails: 6_1 },
|
353
|
+
{ruby: jruby-9.3, rails: 6 },
|
152
354
|
]
|
153
355
|
steps:
|
154
356
|
- uses: actions/checkout@v2
|
@@ -167,6 +369,12 @@ jobs:
|
|
167
369
|
ridk exec sh -c "pacman --sync --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc"
|
168
370
|
- name: Update system-wide gems
|
169
371
|
run: gem update --system
|
372
|
+
- name: Setup Gemfile
|
373
|
+
if: ${{ matrix.rails != '5_2' }}
|
374
|
+
run: |
|
375
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
376
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
377
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
170
378
|
- name: bundle install
|
171
379
|
run: |
|
172
380
|
bundle config set gemfile .\gemfiles\rails${{ matrix.rails }}.gemfile
|
@@ -177,7 +385,5 @@ jobs:
|
|
177
385
|
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
178
386
|
- name: Install downloaded gem
|
179
387
|
run: gem install --local *.gem --verbose
|
180
|
-
- name: Run test to_sql
|
181
|
-
run: rake test:to_sql
|
182
388
|
- name: Run test mssql
|
183
|
-
run: rake test:mssql
|
389
|
+
run: bundle exec rake test:mssql
|
data/Gemfile
CHANGED
@@ -3,22 +3,22 @@ source "https://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
-
gem "sqlite3", '<= 1.3.13', platforms: [:mri
|
7
|
-
gem "mysql2", '0.4.10', platforms: [:mri
|
8
|
-
gem "pg", '< 1', platforms: [:mri
|
6
|
+
gem "sqlite3", '<= 1.3.13', platforms: [:mri]
|
7
|
+
gem "mysql2", '0.4.10', platforms: [:mri]
|
8
|
+
gem "pg", '< 1', platforms: [:mri]
|
9
9
|
|
10
10
|
gem "jdbc-sqlite3", platforms: :jruby
|
11
11
|
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
12
12
|
gem "activerecord-jdbcmysql-adapter", platforms: :jruby
|
13
13
|
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
14
14
|
|
15
|
-
gem "tiny_tds", '~> 1
|
16
|
-
gem "activerecord-sqlserver-adapter", '~>
|
15
|
+
gem "tiny_tds", '~> 2.1', require: false, platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
16
|
+
gem "activerecord-sqlserver-adapter", '~> 6.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
17
17
|
|
18
18
|
gem 'ruby-oci8', platforms: [:mri, :mswin, :x64_mingw, :mingw]
|
19
19
|
gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
|
20
20
|
|
21
|
-
gem 'activesupport', '~>
|
22
|
-
gem 'activemodel', '~>
|
23
|
-
gem 'activerecord', '~>
|
21
|
+
gem 'activesupport', '~> 6.0'
|
22
|
+
gem 'activemodel', '~> 6.0'
|
23
|
+
gem 'activerecord', '~> 6.0'
|
24
24
|
end
|
data/README.md
CHANGED
@@ -130,11 +130,76 @@ t[:birthdate].month.to_sql
|
|
130
130
|
|
131
131
|
t[:birthdate].year.to_sql
|
132
132
|
# => YEAR(my_table.birthdate)
|
133
|
+
```
|
134
|
+
|
135
|
+
### Datetime
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
# datetime difference
|
139
|
+
t[:birthdate] - Time.utc(2014, 3, 3, 12, 41, 18)
|
140
|
+
|
141
|
+
# comparison
|
142
|
+
t[:birthdate] >= '2014-03-03 10:10:10'
|
143
|
+
```
|
144
|
+
|
145
|
+
### Format and Time Zone Conversion
|
146
|
+
|
147
|
+
`format` has two forms:
|
133
148
|
|
149
|
+
```ruby
|
134
150
|
t[:birthdate].format('%Y-%m-%d').to_sql
|
135
151
|
# => DATE_FORMAT(my_table.birthdate, '%Y-%m-%d')
|
136
152
|
```
|
137
153
|
|
154
|
+
Which formats the datetime without any time zone conversion.
|
155
|
+
The second form accepts 2 kinds of values:
|
156
|
+
|
157
|
+
1. String:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
t[:birthdate].format('%Y/%m/%d %H:%M:%S', 'posix/Pacific/Tahiti')
|
161
|
+
# => DATE_FORMAT(CONVERT_TZ(CAST(my_table.birthdate AS datetime), 'UTC', 'posix/Pacific/Tahiti'), '%Y/%m/%d %H:%i:%S') ## MySQL
|
162
|
+
# => TO_CHAR(CAST(my_table.birthdate AS timestamp with time zone) AT TIME ZONE 'posix/Pacific/Tahiti', 'YYYY/MM/DD HH24:MI:SS') ## PostgreSQL
|
163
|
+
# => CONVERT(datetime, my_table.birthdate) AT TIME ZONE 'UTC' AT TIME ZONE N'posix/Pacific/Tahiti' ## SQL Server (& truncated for clarity)
|
164
|
+
# ^^^^^^^^^^^^^^^^^^^^ 🚨 Invalid timezone for SQL Server. Explanation below.
|
165
|
+
```
|
166
|
+
|
167
|
+
which will convert the datetime field to the supplied time zone. This generally
|
168
|
+
means that you're letting the RDBMS decide or infer what is the timezone of the
|
169
|
+
column before conversion to the supplied timezone.
|
170
|
+
|
171
|
+
1. Hash of the form `{ src_time_zone => dst_time_zone }`:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
t[:birthdate].format('%Y/%m/%d %H:%M:%S', { 'posix/Europe/Paris' => 'posix/Pacific/Tahiti' })
|
175
|
+
```
|
176
|
+
|
177
|
+
which will explicitly indicate the original timestamp that should be considered
|
178
|
+
by the RDBMS.
|
179
|
+
|
180
|
+
Warning:
|
181
|
+
|
182
|
+
- ⚠️ Time Zone names are specific to each RDBMS. While `PostgreSQL` and `MySQL`
|
183
|
+
have overlaping names (the ones prefixed with `posix`), you should always
|
184
|
+
read your vendor's documentation. `SQL Server` is a black sheep and has its
|
185
|
+
own conventions.
|
186
|
+
- ⚠️ Daylight saving is managed by the RDBMS vendor. Choose the approptiate time
|
187
|
+
zone name that enforces proper daylight saving conversions.
|
188
|
+
- ☣️ Choosing `GMT+offset` will certainly bypass daylight saving computations.
|
189
|
+
- ☣️ Choosing abbreviate forms like `CET`, which stands for `Central European
|
190
|
+
Time` will behave differently on `PostgreSQL` and `MySQL`. Don't assume
|
191
|
+
uniform behavior, or even a _rational_ one.
|
192
|
+
- ⚠️ Pay attention to the type of the `datetime` column you're working with. For
|
193
|
+
example, in Postgres, a `datetime` can be one of the following types:
|
194
|
+
1. `timestamp with time zone`
|
195
|
+
2. `timestamp without time zone`
|
196
|
+
In the first case, you don't need to supply a conversion hash because postgres
|
197
|
+
knows how to convert it to the desired time zone. However, if you do the same
|
198
|
+
for the second case, you might get surprises, especially if your Postgres
|
199
|
+
installation's default timezone is not `UTC`.
|
200
|
+
- ⚠️ SQLite is not supported.
|
201
|
+
- 🚨 Always test against your setup 🚨
|
202
|
+
|
138
203
|
## Unions
|
139
204
|
|
140
205
|
```ruby
|
data/gemfiles/rails5_2.gemfile
CHANGED
@@ -4,7 +4,7 @@ gem 'rails', '~> 5.2.0'
|
|
4
4
|
gem 'arel', '~> 9'
|
5
5
|
|
6
6
|
group :development, :test do
|
7
|
-
gem 'bigdecimal', '1.3.5'
|
7
|
+
gem 'bigdecimal', '1.3.5', :platforms => [:mri, :mingw, :x64_mingw, :mswin]
|
8
8
|
gem 'activesupport', '~> 5.2.0'
|
9
9
|
gem 'activemodel', '~> 5.2.0'
|
10
10
|
gem 'activerecord', '~> 5.2.0'
|
@@ -20,12 +20,12 @@ group :development, :test do
|
|
20
20
|
gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0' if ENV.has_key? 'ORACLE_HOME'
|
21
21
|
|
22
22
|
# for JRuby
|
23
|
-
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v52.
|
23
|
+
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v52.7', platforms: :jruby
|
24
24
|
gem "jdbc-sqlite3", platforms: :jruby
|
25
25
|
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
26
26
|
gem "activerecord-jdbcmysql-adapter", platforms: :jruby
|
27
27
|
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
28
|
-
gem "activerecord-
|
28
|
+
gem "activerecord-jdbcsqlserver-adapter", '~> 52.0', platforms: :jruby
|
29
29
|
end
|
30
30
|
|
31
31
|
gemspec path: "../"
|
data/gemfiles/rails6.gemfile
CHANGED
@@ -9,8 +9,8 @@ group :development, :test do
|
|
9
9
|
gem 'activerecord', '~> 6.0.0'
|
10
10
|
|
11
11
|
gem "sqlite3", '~> 1.4', platforms: [:mri]
|
12
|
-
|
13
|
-
|
12
|
+
gem "mysql2", '0.5.2', platforms: [:mri]
|
13
|
+
gem "pg",'< 1.0.0', platforms: [:mri]
|
14
14
|
|
15
15
|
gem "tiny_tds", platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
16
16
|
gem "activerecord-sqlserver-adapter", '~> 6.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
@@ -19,12 +19,11 @@ group :development, :test do
|
|
19
19
|
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
20
20
|
|
21
21
|
# for JRuby
|
22
|
-
gem 'activerecord-jdbc-adapter', platforms: :jruby
|
22
|
+
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v60.4', platforms: :jruby
|
23
23
|
gem "jdbc-sqlite3", platforms: :jruby
|
24
24
|
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
25
25
|
gem "activerecord-jdbcmysql-adapter", platforms: :jruby
|
26
26
|
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
27
|
-
gem "activerecord-jdbcmssql-adapter", platforms: :jruby
|
28
27
|
end
|
29
28
|
|
30
29
|
gemspec path: "../"
|
data/gemfiles/rails6_1.gemfile
CHANGED
@@ -19,12 +19,11 @@ group :development, :test do
|
|
19
19
|
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
20
20
|
|
21
21
|
# for JRuby
|
22
|
-
gem 'activerecord-jdbc-adapter', platforms: :jruby
|
22
|
+
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v61.1', platforms: :jruby
|
23
23
|
gem "jdbc-sqlite3", platforms: :jruby
|
24
24
|
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
25
25
|
gem "activerecord-jdbcmysql-adapter", platforms: :jruby
|
26
26
|
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
27
|
-
gem "activerecord-jdbcmssql-adapter", platforms: :jruby
|
28
27
|
end
|
29
28
|
|
30
29
|
gemspec path: "../"
|
data/gemfiles/rails7.gemfile
CHANGED
@@ -8,23 +8,15 @@ group :development, :test do
|
|
8
8
|
gem 'activemodel', '~> 7.0.1'
|
9
9
|
gem 'activerecord', '~> 7.0.1'
|
10
10
|
|
11
|
-
gem "sqlite3", '~> 1.4', platforms: [:mri
|
12
|
-
gem "mysql2", '0.5.2', platforms: [:mri
|
13
|
-
gem "pg",'~> 1.1', platforms: [:mri
|
11
|
+
gem "sqlite3", '~> 1.4', platforms: [:mri]
|
12
|
+
gem "mysql2", '0.5.2', platforms: [:mri]
|
13
|
+
gem "pg",'~> 1.1', platforms: [:mri]
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
gem "tiny_tds", platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
16
|
+
gem "activerecord-sqlserver-adapter", '~> 7.0.0.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
17
17
|
|
18
18
|
gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
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
20
|
end
|
29
21
|
|
30
22
|
gemspec path: "../"
|
@@ -40,8 +40,8 @@ module ArelExtensions
|
|
40
40
|
ArelExtensions::Nodes::Duration.new "s", self
|
41
41
|
end
|
42
42
|
|
43
|
-
def format(tpl)
|
44
|
-
ArelExtensions::Nodes::Format.new [self, tpl]
|
43
|
+
def format(tpl, time_zone = nil)
|
44
|
+
ArelExtensions::Nodes::Format.new [self, tpl, time_zone]
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ArelExtensions
|
2
|
+
|
3
|
+
#
|
4
|
+
# column_of
|
5
|
+
#
|
6
|
+
# Before the creation of these methods, getting the column name was done
|
7
|
+
# uniquely through the code found in `column_of_via_arel_table`.
|
8
|
+
#
|
9
|
+
# This turned out to be unreliable, most notably when using adapters that do
|
10
|
+
# not come with activerecord standard batteries. SQL Server is the most
|
11
|
+
# notorious example.
|
12
|
+
#
|
13
|
+
# Currently, we're using a needlessly complicated way to address this issue.
|
14
|
+
# Different versions of activerecord are behaving differently; the public APIs
|
15
|
+
# do not seem to come with any guarantees, so we need to be sure that we're
|
16
|
+
# coveing all these cases.
|
17
|
+
|
18
|
+
def self.column_of_via_arel_table(table_name, column_name)
|
19
|
+
begin
|
20
|
+
Arel::Table.engine.connection.schema_cache.columns_hash(table_name)[column_name]
|
21
|
+
rescue NoMethodError
|
22
|
+
nil
|
23
|
+
rescue Exception => e
|
24
|
+
puts "Failed to fetch column info for #{table_name}.#{column_name} ."
|
25
|
+
puts "This should never be reached."
|
26
|
+
puts "#{e.class}: #{e}"
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.column_of(table_name, column_name)
|
32
|
+
use_arel_table = !ActiveRecord::Base.connected? || \
|
33
|
+
(ActiveRecord::Base.connection.pool.respond_to?(:schema_cache) && ActiveRecord::Base.connection.pool.schema_cache.nil?)
|
34
|
+
|
35
|
+
if use_arel_table
|
36
|
+
column_of_via_arel_table(table_name, column_name)
|
37
|
+
else
|
38
|
+
if ActiveRecord::Base.connection.pool.respond_to?(:pool_config)
|
39
|
+
ActiveRecord::Base.connection.pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
|
40
|
+
elsif ActiveRecord::Base.connection.pool.respond_to?(:schema_cache)
|
41
|
+
ActiveRecord::Base.connection.pool.schema_cache.columns_hash(table_name)[column_name]
|
42
|
+
else
|
43
|
+
puts ">>> We really shouldn't be here #{table_name}.#{column_name}"
|
44
|
+
column_of_via_arel_table(table_name, column_name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|